本帖最后由 哪里需要我了 于 2024-12-25 17:56 编辑
while循环里面就这简单的几行,只有第一次读取成功了,执行一次i2c_memory_read_int以后SCL引脚就被拉低了,拿的是官方历程里面的communication_int初始化代码,只改了下引脚,用i2c_master_transmit_int和i2c_master_receive_int也是差不多效果,咋办?
if ((i2c_status = i2c_memory_read_int(&hi2cx, I2Cx_ADDRESS, 0x09, rx_buf, sizeof(rx_buf), I2C_TIMEOUT)) != I2C_OK) {
}
if(i2c_wait_end(&hi2cx, I2C_TIMEOUT) != I2C_OK)
{
// error_handler(i2c_status);
}
delay_ms(500);
at32_led_toggle(LED2);
之前用STM32验证I2C从设备功能正常,也用的硬件I2C,难道AT的硬件I2C比ST还难用么?大家用的是软件模拟还是硬件? uint8_t read_voltage_cmd = 0x09;
uint8_t data_received[2];
uint16_t device_address = 0x16;
if (HAL_I2C_Master_Transmit(&hi2c1, device_address, &read_voltage_cmd, 1, HAL_MAX_DELAY) != HAL_OK) {
// 传输错误处理
}
if (HAL_I2C_Master_Receive(&hi2c1, device_address, data_received, sizeof(data_received), HAL_MAX_DELAY) != HAL_OK) {
// 接收错误处理
}
|