[Xianji HPM6750 Review] + Software simulation IIC reads the temperature and humidity sensor values
[Copy link]
I had some things to do in the middle and stopped updating for a while. Next, we will continue our development and testing. Today, I will make a simple software to simulate IIC to read the temperature and humidity data. The sensor I use is the SHT20 that I have used before. Later, I will make some other sensors to enrich our sensor use cases.
For software simulation, we still need to create some new files, and we will do it for these two.
void IIC_Init(void)
{
uint32_t pad_ctl = IOC_PAD_PAD_CTL_OD_SET(1);
HPM_IOC->PAD[IOC_PAD_PD24].FUNC_CTL = IOC_PD24_FUNC_CTL_GPIO_D_24;
HPM_IOC->PAD[IOC_PAD_PD25].FUNC_CTL = IOC_PD25_FUNC_CTL_GPIO_D_25;
gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOD, 24, 1);
gpio_set_pin_output_with_initial(HPM_GPIO0, GPIO_DO_GPIOD, 25, 1);
IIC_SpeedCtl(5);
SDA_H; //拉高SDA线,处于空闲状态
SCL_H; //拉高SCL线,处于空闲状态
}
This is our IO initialization, which selects the PD24 and PD25 ports of the P2 port. Initialize it to the output configuration first. In fact, SDA needs to be read, so we need to make two configurations in the next file, one is IO output, and the other is to change its output to input.
Here are the specific IO operations. We replaced them with the library we compiled earlier.
Then I connected my logic analyzer and could see that both sending and receiving were normal.
Then the serial port prints out. It can be displayed, which is normal.
The hardware connection is as above. This debugging is basically based on the library history given by the editor. Later we will see if the hardware can be driven. At the same time, the library provided by the editor is different from the one we often develop for STM32 microcontrollers, so we need to be familiar with it.
|