读取数据感觉好像不太稳定。设想的是一次读取30个数据。连续读取。
开始数据顺序正常
AA FF 03 00 OE 03 B186 10 00 68 01 00 00 00 00 00 00 00 00 00 00000000 00 00 00 55 CC
持续一段时间就变成下面这样了。
55 CC AA FF 03 00 OE 03 B186 10 00 68 01 00 00 00 00 00 00 00 00 00 00000000 00 00 00
这个状态的数据好像,好像,好像是能一直保持。。。后面打印的日志都是这样子的。不知道后面会不会越变越离谱。
有什么办法可以保证每次读取接到的数据都是正确顺序的吗。就想一次把数据拿全了。
代码大概是下面这样的。
#include "bflb_mtimer.h"
#include "board.h"
#include "bflb_uart.h"
#include "bflb_gpio.h"
#include "FreeRTOS.h"
#include "task.h"
#define DBG_TAG "MAIN"
#include "log.h"
struct bflb_device_s *rd03d;
uint8_t UART_RECEIVE_BUFFER[30];
void _rd03dTask(void* pvParameters){
while (1)
{
memset(UART_RECEIVE_BUFFER, 0, sizeof(UART_RECEIVE_BUFFER));
int len = bflb_uart_get(rd03d, UART_RECEIVE_BUFFER, 30);
if(len > 0){
for (size_t i = 0; i < sizeof(UART_RECEIVE_BUFFER); i++){
printf("0x%2x", UART_RECEIVE_BUFFER[i]);
}
LOG_E("\r\n");
}
vTaskDelay(500/ portTICK_RATE_MS);
}
}
int main(void)
{
board_init();
struct bflb_device_s * gpio = bflb_device_get_by_name("gpio");
bflb_gpio_uart_init(gpio, GPIO_PIN_23, GPIO_UART_FUNC_UART1_TX);
bflb_gpio_uart_init(gpio, GPIO_PIN_24, GPIO_UART_FUNC_UART1_RX);
rd03d = bflb_device_get_by_name("uart1");
struct bflb_uart_config_s conf = {
.baudrate = 256000,
.data_bits = UART_DATA_BITS_8,
.stop_bits = UART_STOP_BITS_1,
.parity = UART_PARITY_NONE,
.flow_ctrl = UART_FLOWCTRL_NONE,
.rx_fifo_threshold = 7,
.tx_fifo_threshold = 7
};
bflb_uart_init(rd03d, &conf);
xTaskCreate(_rd03dTask, (char*)"rd03d", 1024, NULL, 1, NULL);
vTaskStartScheduler();
while (1) {
}
}
|