This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I'm using CC2340R5 simplelink_lowpower_f3_sdk_7_40_00_64 example code basic_ble.
I'm making connection with Apk using peripheral mode. Whenever Apk sends any request to BLE, on that request I need to respond by writing the same request to my controller which is connected to BLE's UART.
Controller then sends a response to the same request.
Currently, I'm able to send the request to controller through UART_2, but I'm not able to read the response sent on the UART_2.
Below is my code of UART configurations:
1)This is the thread I've created where UART initializes. (I took the reference from example code uart2callback given in resource explorer.)
void mainThread() { char input; const char echoPrompt[] = "Echoing characters:\r\n"; UART2_Params uartParams; int32_t semStatus; uint32_t status = UART2_STATUS_SUCCESS; uint8_t tempbuf[64] = {0}; /* Create semaphore */ // semStatus = sem_init(&sem, 0, 0); // if (semStatus != 0) // { // /* Error creating semaphore */ // // while (1) {} // } /* Create a UART in CALLBACK read mode */ UART2_Params_init(&uartParams); uartParams.readMode = UART2_Mode_CALLBACK; uartParams.readCallback = callbackFxn; uartParams.baudRate = 115200; uart_handle = UART2_open(CONFIG_DISPLAY_UART, &uartParams); }
2)This is the callback function. Doing nothing here.
void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status) { if (status != UART2_STATUS_SUCCESS) { /* RX error occured in UART2_read() */ // while (1) {} } numBytesRead = count; // sem_post(&sem); }
3)uart_handle is taken global. Calling these two functions where I get the request from apk.
UART2_write(uart_handle, newValue, len, NULL); UART2_read(uart_handle, newValue, sizeof(newValue), NULL);
Here, uart write works properly. I get the exact data on UART but when reading I'm not getting any data.
I've disabled the function Menu_start();
Am I missing something here?
Regards,
Rushikesh.
Hi Rushikesh,
Thank you for reaching the support,
Several points reach my attention, I see your main thread is terminating could you try adding an infinite loop with a delay?
Additionally, the operation mode of UART is callback but you're not using the callback function, I would suggest trying the blocking mode or the non-blocking mode please find more information in the uart2 driver UART2.h File Reference (ti.com)
I hope this help,
Tanguy
Hello Tanguy,
Thanks for your suggestions.
Made below changes as per you suggested and it worked!
1)I've set the UART operation mode to UART2_Mode_BLOCKING.
uartParams.readMode = UART2_Mode_BLOCKING;
2)Additionally, I'm calling the mainthread(); whenever there will be a request from Apk on the characteristic attribute.
And closing UART after reading the data into the buffer.
mainThread(); len = strlen(newValue); /* Pass NULL for bytesWritten since it's not used in this example */ UART2_write(uart_handle, newValue, len, NULL); memset(newValue,0,sizeof(newValue)); status = UART2_read(uart_handle, newValue, sizeof(newValue), NULL); UART2_close(uart_handle);
Suggest me if there's anything I can modify or optimize into the code.
Regards,
Rushikesh.