我正在尝试在 UART0 上接收一个字符串,并在最基本的步骤中获取 RX FIFO 缓冲区中可用的字节数。
我试着使用神奇的公式
fifo_len = (READ_PERI_REG(UART_STATUS(UART0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT;
在回调函数中,我从我的 PC 将 char 发送到 ESP 的 RX 引脚上。
但是fifo_len总是低于我实际发送的实际字符数,并且几乎总是 0,除非我以非常短的间隔调用我的回调函数,比如 10 毫秒。在这种情况下,计数开始是正确的,直到来自 SDK 的 11500 波特的某个神秘的 printf(以“n”结尾)刷新了 UART 缓冲区并重置了计数(因为似乎 printfed 或在 UART 上发送的任何“n”都会刷新缓冲区...... -_- UART 仍然让我感到困惑:
https://bbs.espressif.com/viewtopic.php?f=7&t=9581).
您知道如何获取FIFO中接收的字节数吗?
.....
我正在使用使用 esp-open-sdk 构建的 NONOS-SDK 2.2.0。
The mysterious printf in ques
tion is like "tail 4rr chksum 0xr1c, rn csum 0x1c..."
我的测试代码是:
#include "ets_sys.h"
#include "osapi.h"
#include "os_type.h"
#include "user_interface.h" // Provide init_done_cb()
#include "espconn.h" // Provides the UDP/TCP functions
#include "../esp-open-sdk/sdk/driver_lib/include/driver/uart.h"
静态os_timer_t readUartTimer_st;
/**
* Callback called on each tick of the timer, for the moment just to print the number of bytes available...
*/
void ReadUartTimerCb(void)
{
uint8 fifo_len;
fifo_len = (READ_PERI_REG(UART_STATUS(UART0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT;
os_printf("UART0: len = %d n", fifo_len);
}
/**
* Callback called when the ESP is fully initialized.
*/
void PostInitCb(void)
{
// Hello
gpio_init();
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
GPIO_OUTPUT_SET(GPIO_ID_PIN(0u), 0);
// Setting up UART0
uart_init(BIT_RATE_9600, BIT_RATE_9600);
os_timer_disarm(&readUartTimer_st);
os_timer_setfn(&readUartTimer_st, (os_timer_func_t *) ReadUartTimerCb, NULL);
os_timer_arm(&readUartTimer_st, 100, true);
}
/**
* Main entry point of our programm
*/
无效 user_init()
{
system_init_done_cb(PostInitCb);
}