generated from hulk/gd32e23x_template
recevice function
This commit is contained in:
parent
44cf0426e5
commit
de94a72f72
@ -102,17 +102,17 @@ int LDC1612_IIC_read_16bits(void) {
|
|||||||
uint16_t raw_temp = 0;
|
uint16_t raw_temp = 0;
|
||||||
uint16_t timeout = 0;
|
uint16_t timeout = 0;
|
||||||
|
|
||||||
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
// i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
||||||
|
|
||||||
while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) //判断IIC总线是否忙,发送起始信号
|
// while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) //判断IIC总线是否忙,发送起始信号
|
||||||
timeout++;
|
// timeout++;
|
||||||
if (timeout < I2C_TIME_OUT) {
|
// if (timeout < I2C_TIME_OUT) {
|
||||||
i2c_start_on_bus(I2C0);
|
i2c_start_on_bus(I2C0);
|
||||||
timeout = 0;
|
// timeout = 0;
|
||||||
} else {
|
// } else {
|
||||||
printf("err\r\n");
|
// printf("err\r\n");
|
||||||
return -1; // 超时返回错误
|
// return -1; // 超时返回错误
|
||||||
}
|
// }
|
||||||
|
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_SBSEND) && (timeout < I2C_TIME_OUT)) //判断起始位是否发送,设置sensor地址并设置为写
|
while (!i2c_flag_get(I2C0, I2C_FLAG_SBSEND) && (timeout < I2C_TIME_OUT)) //判断起始位是否发送,设置sensor地址并设置为写
|
||||||
timeout++;
|
timeout++;
|
||||||
@ -181,7 +181,7 @@ int LDC1612_IIC_read_16bits(void) {
|
|||||||
return -8; // 超时返回错误
|
return -8; // 超时返回错误
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_ack_config(I2C0, I2C_ACK_DISABLE); // 关闭发送ACK,它会在下一个字节完成后发送NAK
|
// i2c_ack_config(I2C0, I2C_ACK_DISABLE); // 关闭发送ACK,它会在下一个字节完成后发送NAK
|
||||||
|
|
||||||
// 读取第二个字节的数据
|
// 读取第二个字节的数据
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE) && (timeout < I2C_TIME_OUT)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_RBNE) && (timeout < I2C_TIME_OUT)) {
|
||||||
|
25
src/main.c
25
src/main.c
@ -106,9 +106,9 @@ int main(void)
|
|||||||
|
|
||||||
// uint16_t data[3] = {0};
|
// uint16_t data[3] = {0};
|
||||||
|
|
||||||
// I2C _scan();
|
// I2C_scan();
|
||||||
|
|
||||||
delay_ms(200);
|
delay_ms(1000);
|
||||||
|
|
||||||
// while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY));
|
// while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY));
|
||||||
// i2c_start_on_bus(I2C0);
|
// i2c_start_on_bus(I2C0);
|
||||||
@ -136,21 +136,26 @@ int main(void)
|
|||||||
//
|
//
|
||||||
// i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
// i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
||||||
|
|
||||||
iicSendData();
|
// iicSendData();
|
||||||
iicReceiveData();
|
// iicReceiveData();
|
||||||
|
|
||||||
// int result = 0;
|
int result = 0;
|
||||||
// result = LDC1612_IIC_read_16bits();
|
result = LDC1612_IIC_read_16bits();
|
||||||
// printf("result = %d\r\n", result);
|
printf("result = %d\r\n", result);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
// printf("OK!!!\r\n");
|
|
||||||
//
|
|
||||||
// delay_ms(1000);
|
delay_ms(1000);
|
||||||
|
printf("OK!!!\r\n");
|
||||||
|
// iicSendData();
|
||||||
|
|
||||||
|
// i2c_flag_clear(I2C0, I2C_FLAG_I2CBSY);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user