STM32 GPIO模拟I2C的SHT20温湿度采样

要用GPIO模拟I2C,那么首先就得弄清楚I2C的时序。

1.I2C总线通信时序

2.起始与结束时序

 

//起始信号
uint8_t I2c_StartCondition()
{
        uint8_t rv = NO_ERROR;
        SDA_OUT();
        SCL_OUT();
        /* StartCondition(S): A high to low transition on the SDA line while SCL is high.
        _______
        SCL:   |___
        _____
        SDA: |_____
        */
        SDA_H();
        delay_us(2);
        SCL_H();
        delay_us(2);
        SDA_L();//先于SCL前拉低
        delay_us(2);
        SCL_L();//拉低SCL便于之后的操作
        delay_us(2);
        return rv;
        
}  
//终止信号
uint8_t I2c_StopCondition(void)
{
        uint8_t rv = NO_ERROR;
        SDA_OUT();
        /* StopCondition(P): A low to high transition on the SDA line while SCL is high.
        ————————————
        SCL:        — — —
                 _____
        SDA: ___|
        */
        SCL_L();
        SDA_L();
 
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值