2422 views|7 replies

1452

Posts

1

Resources
The OP
 

[ESK32-360 Review] + Sensor Measurement and Output Display [Copy link]

 This post was last edited by jinglixixi on 2020-8-23 09:17

1. I2C bus simulation and BH1750 light intensity detection

BH1750 is a digital light intensity sensor based on the I2C interface. We can use the vacant pins of the SD card interface to simulate the I2C interface to drive the sensor for light intensity detection.

Overall composition

BH1750 connection relationship:

SCL---PC11

SDA---PC12

The statements for outputting high and low levels are:

#define SCL_Set() HT_GPIOC->SRR = GPIO_PIN_11

#define SCL_Clr() HT_GPIOC->RR = GPIO_PIN_11

#define SDA_Set() HT_GPIOC->SRR = GPIO_PIN_12

#define SDA_Clr() HT_GPIOC->RR = GPIO_PIN_12

The function for configuring the GPIO port pins is:

void IIC_Init(void)
{
 HT32F_DVB_ClockConfig();
GPIO_PullResistorConfig(HT_GPIOC, GPIO_PIN_12, GPIO_PR_DISABLE);
 GPIO_DriveConfig(HT_GPIOC, GPIO_PIN_12, GPIO_DV_8MA);
 GPIO_DirectionConfig(HT_GPIOC, GPIO_PIN_12, GPIO_DIR_OUT);
 GPIO_PullResistorConfig(HT_GPIOC, GPIO_PIN_11, GPIO_PR_DISABLE);
 GPIO_DriveConfig(HT_GPIOC, GPIO_PIN_11, GPIO_DV_8MA);
 GPIO_DirectionConfig(HT_GPIOC, GPIO_PIN_11, GPIO_DIR_OUT);
}

The function for reading light intensity is:

void Get_Sunlight_Value()
{
 int dis_data=0;
 float temp;
 char i=0;
 unsigned int sd;
 Single_Write_BH1750(0x01);
 Single_Write_BH1750(0x10);
 Delayms(180);
 Multiple_Read_BH1750();
 for(i=0;i<3;i++)
 dis_data=gHelloString[0];
 dis_data=(dis_data<<8)+gHelloString[1];
 temp=(float)dis_data/1.2;
 sd=temp;
 gHelloString[0] = sd/10000+'0';
 gHelloString[1] = sd% 10000/1000+'0';
 gHelloString[2] = sd % 1000/100+'0';
 gHelloString[3] = sd % 100/10+'0';
 gHelloString[4] = sd % 10+'0';
 UxART_TxTest();
}

The main function of light intensity detection is:

int main(void)
{
	SYSTICK_ClockSourceConfig(SYSTICK_SRC_STCLK);
    SYSTICK_SetReloadValue(SystemCoreClock / 8 / 1000); 
    SYSTICK_IntConfig(ENABLE); 
    
    HT32F_DVB_ClockConfig
	
    UxART_Configuration();
	IIC_Init();
	while(1)
	{
		 Get_Sunlight_Value();
         Delayms(1000);
	}
}

After the program is downloaded, its running results are shown in the figure.

Figure 3 BH1750 test results

2. BMP085 temperature and pressure detection

BMP085 is a digital sensor based on I2C interface, which is mainly used to measure temperature, air pressure and altitude. We can drive the sensor by simulating I2C interface to perform measurement.

Overall composition

The connection relationship between BMP085 and MCU is as follows:

SDA---PC12

SCL---PC11

The initialization function of BMP085 is:

void Init_BMP085()
{
 ac1 = Multiple_read(0xAA);
 ac2 = Multiple_read(0xAC);
 ac3 = Multiple_read(0xAE);
 ac4 = Multiple_read(0xB0);
 ac5 = Multiple_read(0xB2);
 ac6 = Multiple_read(0xB4);
 b1 = Multiple_read(0xB6);
 b2 = Multiple_read(0xB8);
 mb = Multiple_read(0xBA);
 mc = Multiple_read(0xBC);
 md = Multiple_read(0xBE);
}

The function for reading temperature and pressure is:

void bmp085Convert()
{
 unsigned int ut;
 unsigned long up;
 long x1, x2, b5, b6, x3, b3, p;
 unsigned long b4, b7;

 ut = bmp085ReadTemp();
 up = bmp085ReadPressure();
 x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
 x2 = ((long) mc << 11) / (x1 + md);
 b5 = x1 + x2;
 temperature = ((b5 + 8) >> 4);
    b6 = b5 - 4000;
    x1 = (b2 * (b6 * b6)>>12)>>11;
    x2 = (ac2 * b6)>>11;
    x3 = x1 + x2;
    b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
  x1 = (ac3 * b6)>>13;
    x2 = (b1 * ((b6 * b6)>>12))>>16;
    x3 = ((x1 + x2) + 2)>>2;
    b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
    b7 = ((unsigned long)(up - b3) * (50000>>OSS));
    if (b7 < 0x80000000)
  p = (b7<<1)/b4;
    else
  p = (b7/b4)<<1;
 x1 = (p>>8) * (p>>8);
 x1 = (x1 * 3038)>>16;
 x2 = (-7357 * p)>>16;
 pressure = p+((x1 + x2 + 3791)>>4);
}

The main procedure of the detection is:

int main(void)
{
       SYSTICK_ClockSourceConfig(SYSTICK_SRC_STCLK);
      SYSTICK_SetReloadValue(SystemCoreClock / 8 / 1000);
      SYSTICK_IntConfig(ENABLE);
 UxART_Configuration();
 IIC_Init();
 Init_BMP085();
 while(1)
 {
 bmp085Convert();
 ConvTemperature();
 ConvPressure();
 ConvAltitude();
         Delayms(1000);
 }
}

Detection value output display

This post is from Domestic Chip Exchange

Latest reply

Thanks for sharing   Details Published on 2021-4-13 11:56
 
 

7422

Posts

2

Resources
2
 

Why do we always need io to simulate i2c?

This post is from Domestic Chip Exchange

Comments

Haha, it’s useful!  Details Published on 2020-8-24 00:02
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1452

Posts

1

Resources
3
 
freebsder posted on 2020-8-23 21:50 Why do we always need io to simulate i2c?

Haha, it’s useful!

This post is from Domestic Chip Exchange
 
 
 

1w

Posts

204

Resources
4
 

Hetai ESK32-360 development board review
Summary post: https://en.eeworld.com/bbs/thread-1134246-1-1.html

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

http://en.eeworld.com/bbs/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

661

Posts

0

Resources
5
 

Thanks for sharing

This post is from Domestic Chip Exchange
 
 
 

1452

Posts

1

Resources
6
 

This post is from Domestic Chip Exchange
 
 
 

661

Posts

0

Resources
7
 

Thanks for sharing

This post is from Domestic Chip Exchange

Comments

Thanks for your support  Details Published on 2021-4-14 08:16
 
 
 

1452

Posts

1

Resources
8
 

Thanks for your support

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list