单片机解密STM32单片机的IIC读取AHT20 AHT21温湿度
- 单片机解密#include "stm32f10x.h"
- 单片机解密#include "AHT20-21_DEMO_V1_3.h"
- void Delay_N10us(uint32_t t)//延时函数
- {
- uint32_t k;
- while(t--)
- {
- for (k = 0; k < 2; k++);//110
- }
- }
- void SensorDelay_us(uint32_t t)//延时函数
- {
-
- for(t = t-2; t>0; t--)
- {
- Delay_N10us(1);
- }
- }
- void Delay_4us(void) //延时函数
- {
- Delay_N10us(1);
- Delay_N10us(1);
- Delay_N10us(1);
- Delay_N10us(1);
- }
- void Delay_5us(void) //延时函数
- {
- Delay_N10us(1);
- Delay_N10us(1);
- Delay_N10us(1);
- Delay_N10us(1);
- Delay_N10us(1);
- }
- void Delay_1ms(uint32_t t) //延时函数
- {
- while(t--)
- {
- SensorDelay_us(1000);//////延时1ms
- }
- }
- void AHT20_Clock_Init(void) //延时函数
- {
- RCC_APB2PeriphClockCmd(CC_APB2Periph_GPIOB,ENABLE);
- }
- void SDA_Pin_Output_High(void) //将PB15配置为输出 , 并设置为高电平, PB15作为I2C的SDA
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB,& GPIO_InitStruct);
- GPIO_SetBits(GPIOB,GPIO_Pin_15);
- }
- void SDA_Pin_Output_Low(void) //将P15配置为输出 并设置为低电平//SDA配置为浮空输出
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOB,& GPIO_InitStruct);
- GPIO_ResetBits(GPIOB,GPIO_Pin_15);
- }
- void SDA_Pin_IN_FLOATING(void) //SDA配置为浮空输入
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;//
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init( GPIOB,&GPIO_InitStruct);
- }
- void SCL_Pin_Output_High(void) //SCL输出高电平,P14作为I2C的SCL
- {
- GPIO_SetBits(GPIOB,GPIO_Pin_14);
- }

芯片解密