问答

汇集网友智慧,解决技术难题

gakiki

TA的家园币:12  

  • gd32l23cct6 硬件i2c 等待TI / RBNE标志位超时

    gd32l23cct6芯片在硬件i2c读写过程中会偶尔出现write函数在TI标志位超时跳出,read函数在RBNE标志位超时跳出,TIMEOUT时间测试200ms+,在这两个标志位超时异常跳出导致i2c通信时序缺少stop位,bsy标志位一直位1,i2c再也无法继续通信,一定要通过复位i2c外设才能解决。硬件i2c驱动代码去下intgd32_i2c_write(unsignedcharbus,unsignedshortaddr,unsignedchar*data,unsignedintdata_len){drv_i2c_mgr_t*i2c_mgr=NULL;unsignedinttimeout=DRV_I2C_TIME_OUT;unsignedintidx;if(bus>=DRV_I2C_BUS_MAX){return-1;}i2c_mgr=&s_st_i2c_mgr;if(0==i2c_mgr->is_init){return-1;}/*waituntilI2Cbusisidle*/timeout=DRV_I2C_TIME_OUT;i2c_master_addressing(i2c_mgr->periph,addrperiph,data_len);while(i2c_flag_get(i2c_mgr->periph,I2C_FLAG_I2CBSY)){if((timeout--)==0){return-1;}}/*sendastartconditiontoI2Cbus*/timeout=DRV_I2C_TIME_OUT;i2c_start_on_bus(i2c_mgr->periph);/*waituntilthetransmitdatabufferisempty*/I2C_STAT(i2c_mgr->periph)|=I2C_STAT_TBE;while(!i2c_flag_get(i2c_mgr->periph,I2C_FLAG_TBE)){if((timeout--)==0){return-1;}}for(idx=0;idx<data_len;idx++){/*datatransmission*/timeout=DRV_I2C_TIME_OUT;i2c_data_transmit(i2c_mgr->periph,data);while(!i2c_flag_get(i2c_mgr->periph,I2C_FLAG_TI)){if((timeout--)==0){LOG_DIRECT_ERR("ti\r\n");return-1;}}}timeout=DRV_I2C_TIME_OUT;while(!i2c_flag_get(i2c_mgr->periph,I2C_FLAG_TC)){if((timeout--)==0){return-1;}}/*sendastopconditiontoI2Cbus*/i2c_stop_on_bus(i2c_mgr->periph);/*waituntilstopconditiongenerate*/while(!i2c_flag_get(i2c_mgr->periph,I2C_FLAG_STPDET)){if((timeout--)==0){return-1;}}/*cleartheSTPDETbit*/i2c_flag_clear(i2c_mgr->periph,I2C_FLAG_STPDET);return0;}intgd32_i2c_read(unsignedcharbus,unsignedsh

    GD32 I2c

    2023-09-21 11