-
GD32H757VGT6的硬件I2C问题
GD32H757VGT6的硬件I2C读写都一直卡在while(!i2c_flag_get(I2C0,I2C_FLAG_ADDSEND)),地址确认没有问题,时序是跟着手册里的时序表配置的,有大佬知道是为什么吗代码如下:初始化/*禁用I2C外设*/i2c_deinit(I2C0);//禁用从机地址i2c_address_disable(I2C0);/*配置时序(100kHz,满足t_VD;DAT≤3.45μs)*/i2c_timing_config(I2C0,14,3,0);//PSC=14,SDADEL=3,SCLDEL=0i2c_master_clock_config(I2C0,65,34);//SCLH=65,SCLL=34→周期≈10μs/*禁用自动结束模式(手动控制STOP条件)*/i2c_automatic_end_disable(I2C0);/*使能I2C*/i2c_enable(I2C0);i2c_nack_enable(I2C0);i2c_bus_timeout_a_config(I2C0,0x96);//超时阈值根据实际时钟调/*单字节写入*/intbyte_write(uint16_taddr,uint8_tdata){/*等待总线空闲*/while(i2c_flag_get(I2C0,I2C_FLAG_I2CBSY));/*配置传输3字节:地址高、地址低、数据*/i2c_transfer_byte_number_config(I2C0,3);/*发送起始条件*/i2c_start_on_bus(I2C0);/*3等待地址发送完成或检测错误*/i2c_master_addressing(I2C0,EEPROM_WRITE_ADDR,I2C_MASTER_TRANSMIT);while(!i2c_flag_get(I2C0,I2C_FLAG_ADDSEND)){if(i2c_flag_get(I2C0,I2C_FLAG_NACK)||i2c_flag_get(I2C0,I2C_FLAG_BERR)||i2c_flag_get(I2C0,I2C_FLAG_LOSTARB)){i2c_stop_on_bus(I2C0);i2c_flag_clear(I2C0,I2C_FLAG_NACK|I2C_FLAG_BERR|I2C_FLAG_LOSTARB);return-1;//错误处理}}i2c_flag_clear(I2C0,I2C_FLAG_ADDSEND);/*发送地址高字节*/i2c_data_transmit(I2C0,(addr>>8));while(!i2c_flag_get(I2C0,I2C_FLAG_TBE)){//等待发送缓冲区空}/*发送地址低字节*/i2c_data_transmit(I2C0,(addr&0xFF));while(!i2c_flag_get(I2C0,I2C_FLAG_TBE)){//等待发送缓冲区空}/*发送数据字节*/i2c_data_transmit(I2C0,data);while(!i2c_flag_get(I2C0,I2C_FLAG_TBE)){//等待发送缓冲区空}/*等待传输完成(TC标志)*/while(!i2c_flag_get(I2C0,I2C_FLA
2025-03-31 1