I'm using CC2652R development kit to communicate a modem via UART interface.
This is the UART configuration i'm using:
UART_Params uart_params; UART_Params_init(&uart_params); uart_params.writeDataMode = UART_DATA_BINARY; uart_params.writeMode = UART_MODE_BLOCKING; uart_params.readDataMode = UART_DATA_BINARY; uart_params.readReturnMode = UART_RETURN_NEWLINE; uart_params.readEcho = UART_ECHO_OFF; uart_params.readMode = UART_MODE_BLOCKING; uart_params.readTimeout = msecs2Tick(ME310G1_READ_TIMEOUT); //5 seconds waiting for modem answer uart_params.baudRate = ME310G1_READ_BAUDRATE;
Since reading in mode 'UART_RETURN_NEWLINE' doesn't work, i'm waiting 5 seconds for every write and read operations - waiting for read timeout to end.
This mechanism works fine for me, except it's taking too much time.
I tried to implement different read method using read mode 'UART_MODE_CALLBACK' (and a callback) in order to speed up read process like this:
read(void * destination, size_t size) { size_t receive = 0; uint8_t * dst = (uint8_t *)destination; int result = 0; while(size > 0 && result != UART_STATUS_ERROR) { //Read single byte char dummy; result = UART_read(g_uart_handle, &dummy, 1); if(result != UART_STATUS_ERROR) { dst[receive] = dummy; receive++; size--; } } }
The problem with this implementation is that i'm reading zeros bytes since the modem doesn't answer back fast enough.
If i'm inserting a small delay after every byte read, i manage to read appropriately part of the responds from the modem.
Is there something i can do in order to solve this issue ?
I can supply further information if needed.
Thx,
Dekel