fix IIC speed

This commit is contained in:
yelvlab 2024-12-07 16:30:43 +08:00
parent 1d1c0fce21
commit e0b9aab103
2 changed files with 14 additions and 10 deletions

View File

@ -44,7 +44,7 @@ typedef enum {
I2C_STOP
} i2c_process_enum;
#define I2C_SPEED 400000
#define I2C_SPEED 100000
#define RCU_IR_GPIO RCU_GPIOF
#define RCU_I2C RCU_I2C0
#define I2C_SCL_PORT GPIOF

View File

@ -101,6 +101,8 @@ void I2C_scan(void) {
uint8_t IIC_read_16bit(uint8_t reg, uint16_t *value) {
uint32_t timeout = 0;
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
// 发送启动信号
i2c_start_on_bus(I2C0);
timeout = 0;
@ -129,7 +131,7 @@ uint8_t IIC_read_16bit(uint8_t reg, uint16_t *value) {
while (!i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) {
if ((timeout++) > I2C_TIME_OUT) return 4; // 超时
}
printf("test1\n");
// 发送从设备地址和读信号
i2c_master_addressing(I2C0, LDC1612_ADDR, I2C_RECEIVER);
timeout = 0;
@ -145,6 +147,8 @@ uint8_t IIC_read_16bit(uint8_t reg, uint16_t *value) {
}
*value = i2c_data_receive(I2C0) << 8; // 读取高8位
// i2c_ack_config(I2C0, I2C_ACK_DISABLE); // 关闭发送ACK它会在下一个字节完成后发送NAK
timeout = 0;
while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE)) {
if ((timeout++) > I2C_TIME_OUT) return 7; // 超时
@ -174,12 +178,12 @@ void LDC1612_read_sensor_infomation(void)
printf("result: %d\n", result);
}
result = IIC_read_16bit(READ_MANUFACTURER_ID, &manufacturer_id);
if (result == 0) {
printf("manufacturer ID: 0x%04X\n", manufacturer_id);
} else {
printf("Failed to read manufacturer ID\n");
printf("result: %d\n", result);
}
// result = IIC_read_16bit(READ_MANUFACTURER_ID, &manufacturer_id);
//
// if (result == 0) {
// printf("manufacturer ID: 0x%04X\n", manufacturer_id);
// } else {
// printf("Failed to read manufacturer ID\n");
// printf("result: %d\n", result);
// }
}