Dear Sirs,
In my current project I use nRF52 and external ADC. I have to send 14 Bytes each 500us using UART to PC.
It is only one way connection where nRF52840 is transmitter.
As I mentioned before, data amount is 14 Bytes and frequency is 2kHz (500us).
I decided to use baudrate 921,6kbit/s. 1 bit stop, no flow control.
I made simple calculation and I expected the data transfer to take less than 200us.
My calculation:
921600bit/s -----> 14B (+1 biy stop) = 144B -----> 144B *1,09us = 156us ---------> + extra time for processing -------> total time for data transfer <200us.
I
This is my code:
/* config */
#define NRFX_UARTE_ENABLED 1
#define NRFX_UARTE0_ENABLED 1
#define NRFX_UARTE1_ENABLED 1
#define NRFX_UART_ENABLED 1
#define NRFX_UART0_ENABLED 1
#define UART_ENABLED 1
#define UART_EASY_DMA_SUPPORT 1
#define UART_LEGACY_SUPPORT 0
#define UART0_ENABLED 1
#define UART0_CONFIG_USE_EASY_DMA 1
#define UART1_ENABLED 1
#define APP_UART_ENABLED 1
#define APP_UART_DRIVER_INSTANCE 1
/* Init UART*/
const app_uart_comm_params_t uartCfg =
{
DIO_DBG_4, /* RX, not used */
DIO_DBG_3, /* TX */
DIO_DBG_5, /* not used */
DIO_DBG_5, /* not used */
APP_UART_FLOW_CONTROL_DISABLED,
false,
NRF_UART_BAUDRATE_921600
};
APP_UART_FIFO_INIT(&uartCfg, 16, 16, uartErrorHandler, APP_IRQ_PRIORITY_LOWEST, errCode);
APP_ERROR_CHECK(errCode);
/* Send data packet via UART */
uint8_t i = 0;
for (i = 0; i < DATA_PACKET_LENGTH; i++)
{
while (app_uart_put(dataPacket[i]) != NRF_SUCCESS);
}
I have made several time measurements of the part in which I am sending data.
I were changing macro DATA_PACKET_LENGTH in range 1-14 and check how long time takes the MCU to go outside for loop (finish data sending). I was really supprised. These are my results:
DATA_PACKET_LENGTH (B) - total time (us )
1 ~13us
2 ~17us
3 ~21us
4 ~47us
5 ~72us
6 ~98us
7 ~123us
10 ~200us
14 ~302us
1. Could you please explain why first Bytes are being sent so fast and after that MCU oprerate so slow (every next Byte is sent in approx 25us)? 15us for each Byte, it meas that overhead is about 150%. What is going on? :)
2. Sending 14B takes more than 300us (and I expected less than 200us). Is it possible to decrease this time? Maybe there are possible changes to make in coonfiguration?
I appreciate any help.thank you