generated from hulk/gd32e23x_template
删除串口发送数据结尾的\r\n,改为main函数的设置关闭stdout缓冲。printf直接输出
This commit is contained in:
parent
4dc9054544
commit
05fb90c727
@ -130,20 +130,24 @@ void USART0_IRQHandler(void) {
|
||||
rx_buffer[rx_index++] = received_data;
|
||||
}
|
||||
|
||||
// printf("len: %d, data: %c\r\n", rx_index, received_data);
|
||||
|
||||
// 检查是否接收到换行符,表示指令结束
|
||||
if (received_data == '\n') {
|
||||
if (calculate_crc(rx_buffer, rx_index - 2) == rx_buffer[rx_index - 2]) {
|
||||
// printf("CRC check success\r\n");
|
||||
// if (received_data == '\n') {
|
||||
if (calculate_crc(rx_buffer, rx_index - 1) == rx_buffer[rx_index - 1]) {
|
||||
// printf("CRC check success");
|
||||
// rx_buffer[rx_index] = '\0'; // 添加字符串结束符
|
||||
process_command(rx_buffer, rx_index); // 处理指令
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
// printf("%c", 0xff);
|
||||
} else {
|
||||
// printf("CRC check failed\r\n");
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF2, 0x00, 0xF2);
|
||||
// printf("CRC check failed");
|
||||
// printf("%c%c%c%c", 0xB5, 0xF2, 0x00, 0xF2);
|
||||
// fflush(stdout);
|
||||
rx_index = 0; // 重置缓冲区索引
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -143,10 +143,10 @@ void ldc1612_iic_get_sensor_infomation(void) {
|
||||
uint8_t data[2] = {0};
|
||||
// ldc1612_iic_read_16bits(READ_MANUFACTURER_ID, data);
|
||||
i2c_read_16bits(LDC1612_ADDR, READ_MANUFACTURER_ID, data);
|
||||
printf("\tManufacturer: 0x%x\r\n", (data[0] << 8) | data[1]);
|
||||
printf("\tManufacturer: 0x%x", (data[0] << 8) | data[1]);
|
||||
// ldc1612_iic_read_16bits(READ_DEVICE_ID, data);
|
||||
i2c_read_16bits(LDC1612_ADDR, READ_DEVICE_ID, data);
|
||||
printf("\tDevice: 0x%x\r\n", (data[0] << 8) | data[1]);
|
||||
printf("\tDevice: 0x%x", (data[0] << 8) | data[1]);
|
||||
}
|
||||
|
||||
uint16_t ldc1612_get_manufacturer_id(void) {
|
||||
|
@ -25,6 +25,7 @@ uint32_t g_eddy_current_value_uint32;
|
||||
\retval none
|
||||
*/
|
||||
int main(void) {
|
||||
setbuf(stdout, NULL);
|
||||
/* configure systick */
|
||||
systick_config();
|
||||
/* configure USART */
|
||||
|
16
src/rs485.c
16
src/rs485.c
@ -50,17 +50,17 @@ void process_command(uint8_t *cmd, size_t length) {
|
||||
} else if (strcmp(combined_str, "M2") == 0) {
|
||||
tempture_value_report();
|
||||
} else {
|
||||
printf("%c%c%c%c%c%c%c\r\n", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF1, 0x00, 0xF1);
|
||||
printf("%c%c%c%c", 0xB5, 0xF1, 0x00, 0xF1);
|
||||
}
|
||||
} else {
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF5, 0x00, 0xF5);
|
||||
printf("%c%c%c%c", 0xB5, 0xF5, 0x00, 0xF5);
|
||||
}
|
||||
} else {
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF3, 0x00, 0xF3);
|
||||
printf("%c%c%c%c", 0xB5, 0xF3, 0x00, 0xF3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ validation_result_t validate_package_header(uint8_t *data) {
|
||||
if (data[0] == 0xD5) {
|
||||
return VALIDATION_SUCCESS;
|
||||
} else {
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF3, 0x00, 0xF3);
|
||||
printf("%c%c%c%c", 0xB5, 0xF3, 0x00, 0xF3);
|
||||
return VALIDATION_CRC_ERROR;
|
||||
}
|
||||
}
|
||||
@ -87,7 +87,7 @@ validation_result_t validate_package_type(uint8_t *data) {
|
||||
if (data[1] == 0x03) {
|
||||
return VALIDATION_SUCCESS;
|
||||
} else {
|
||||
printf("%c%c%c%c\r\n", 0xB5, 0xF3, 0x00, 0xF3);
|
||||
printf("%c%c%c%c", 0xB5, 0xF3, 0x00, 0xF3);
|
||||
return VALIDATION_CRC_ERROR;
|
||||
}
|
||||
}
|
||||
@ -107,7 +107,7 @@ void eddy_current_value_report(void) {
|
||||
// printf("EddyCurrent: %x\r\n", g_eddy_current_value_uint32);
|
||||
printf("%c%c%c", package_header[0], package_header[1], package_header[2]);
|
||||
printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]);
|
||||
printf("%c\r\n", calculate_crc(combined_data, 7));
|
||||
printf("%c", calculate_crc(combined_data, 7));
|
||||
}
|
||||
|
||||
void tempture_value_report(void) {
|
||||
@ -125,5 +125,5 @@ void tempture_value_report(void) {
|
||||
// printf("Temperature: %x\r\n", g_temperature_uint32);
|
||||
printf("%c%c%c", package_header[0], package_header[1], package_header[2]);
|
||||
printf("%c%c%c%c", package_data[0], package_data[1], package_data[2], package_data[3]);
|
||||
printf("%c\r\n", calculate_crc(combined_data, 7));
|
||||
printf("%c", calculate_crc(combined_data, 7));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user