1、How do I read the data received by the serial port in polling mode
I tried it, but I thought it might not work, because the read function only returns successes and failures, not the actual read length
2、Similarly, when the FIFO function is enabled, the maximum number of received data is 16 bytes. If it is less than 16 bytes, we still cannot know the actual number of received data, so we can only receive one byte by one, and cannot read multiple bytes at a time, nor can we read the data received by the serial port in polling
Thanks for posting your question!
It is not necessary to enable FIFO Support in order to control the number of bytes you receive. You could do that in your callback function. Let’s assume that you’ve enabled channel zero in Asynchronous Serial mode (g_uart0). You could create a call back function like this:
/* Callback function */
void g_uart0_callback(uart_callback_args_t *p_args)
/* TODO: add your own code here */
g_uart_event = (uint8_t)p_args->event;
/*In case we get the desired number of bytes
* we reset g_counter_var value to zero again.
if(g_counter_var == TRANSFER_LEN)
SEGGER_RTT_printf(0, "Wanted number of bytes received! \r\n");
//In case character is received
if(UART_EVENT_RX_CHAR == p_args->event)
You could declare a variable uint8_t g_counter_var for example. This variable reflects the number of bytes you receive to each UART Read. In case you receive a byte (condition: if(UART_EVENT_RX_CHAR == p_args->event)) this value increments by one. When this variable gets the desired value (number of bytes you want to receive: TRANSFER_LEN) you could reset the value to zero again and it will take the desired value in next read process. Also for further debugging you could print some messages in it like I did!
I'm sorry It didn't solve my confusion, I've tested the byte by byte approach of using the interrupt callback function. I want to test receiving data in polling mode. ra2 does not have dma. When rtos is used, thread communication is often queued. If byte by byte interrupts are added to the queue, the efficiency is very low. So speed and efficiency can be provided through polling or FIFO
Ok, could you give me more information about your project?
status = R_SCI_UART_Read(&g_uart0_ctrl, p_dest, 16);
I don't know how many bytes I actually read
When you call R_SCI_UART_Read() this call will be non-blocking. The registered callback will be called when all the requested bytes have been received. In your example this will be 16. So, this function will return immediately and the callback will happen later when 16 bytes have been received.
The UART driver maintains a count of remaining bytes to be received before calling the callback. This is in the control structure and is called rx_dest_bytes. So, you could call the read function and then look at this value to see how many bytes are remaining and so how many have been received if necessary. But this is not how the driver is intended to be used. You should be able to work out how it works from looking at the driver source which is provided.
Thanks for your response!
So you want to enable FIFO Support right? In this case, in your example the maximum number of bytes you can receive is 16. The API call, as Ian told you won't be blocking and your program will enter the callback function as soon as 16 bytes will be received. You also told something about that ra2 does not support DMA. In case you want to make your communication process more efficient you could use the DTC module.
DTC stands for Data Transfer Controller, which transfers data from one memory location to another without using the CPU. Memory locations can be addressable peripheral registers or RAM.
In this case you could enable in your UART stack properties DTC Module. To control the exact number of bytes received with the DTC check this link below:
Please could you send me more details about your project like your UART configurations in FSP and some sample code? Also a screenshot from a logic analyzer with your data transmission would be great!