Tool/software:
I have modified the Data Stream Project to enable Peripheral + Central roles and flashed it onto a CC2340R5 device. Another CC2340R5 device is running the unmodified Data Stream Project in the Peripheral role. Both devices establish a BLE connection successfully.
The end device attached to the BLE module supports only a 9600 baud rate, making it essential for the communication to work seamlessly at this baud rate.
I have attached screenshots showing:
// Writing UART data to the peripheral from central device void sendUartToDataIn() { bStatus_t status = SUCCESS; uint16_t offset = 0; uint16_t mtuSize = 200; uint16_t headerSize = 3; // Approximate GATT header size uint16_t maxChunkSize = mtuSize - headerSize; uint16_t dataLength = BufferSize;//strlen((char*)uartReadBuffer); // Total data length attWriteReq_t req; char buffer[40]; // Loop until all data is sent while (offset < dataLength) { // Determine the chunk size for this iteration uint16_t chunkSize = (dataLength - offset > maxChunkSize) ? maxChunkSize : (dataLength - offset); bool chunkSent = false; // Retry sending the current chunk until successful while (!chunkSent) { // Allocate memory for the write request req.pValue = GATT_bm_alloc(0x0, ATT_WRITE_REQ, chunkSize, NULL); if (req.pValue != NULL) { // Set up the request details req.handle = 0x25; // Set handle for DataIn characteristic req.len = chunkSize; req.sig = FALSE; req.cmd = TRUE; // Using Write Command (Write without Response) // Copy data to the request buffer memcpy(req.pValue, uartReadBuffer + offset, chunkSize); // Attempt to send the data chunk // vTaskDelay(pdMS_TO_TICKS(5)); status = GATT_WriteNoRsp(0x0, &req); // vTaskDelay(pdMS_TO_TICKS(10)); if (status == SUCCESS) { chunkSent = true; // Exit retry loop on success offset += chunkSize; // Move to the next chunk // Only clear sent chunk data in `uartReadBuffer` if desired, or keep it until the entire buffer is read } else { // Free the allocated buffer on failure GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ); vTaskDelay(pdMS_TO_TICKS(10)); } } else { // Memory allocation failed; log error and retry after delay UART2_write(uart, "Memory allocation failed\n", strlen("Memory allocation failed\n"), NULL); vTaskDelay(pdMS_TO_TICKS(50)); // Delay before retrying allocation } } } // Reset UART read buffer for new data memset(uartReadBuffer, 0, UART_MAX_READ_SIZE); UART2_read(uart, uartReadBuffer, UART_MAX_READ_SIZE, NULL); // Set up UART for the next data reception } // Reading data at central form peripheral and writing it to UART case ATT_HANDLE_VALUE_NOTI: { // Handle incoming notification data uint16_t handle = gattMsg->msg.handleValueNoti.handle; uint8_t *pValue = gattMsg->msg.handleValueNoti.pValue; uint16_t len = gattMsg->msg.handleValueNoti.len; uint16_t bytesWritten = 0; uint16_t chunkSize = 200; // Define the max UART write size (200 bytes in this case) // snprintf(buffer, sizeof(buffer), "Size : %d\n", len); // UART2_write(uart, buffer, strlen(buffer), NULL); // Loop to write data to UART in manageable chunks while (bytesWritten < len) { uint16_t bytesToWrite = (len - bytesWritten) > chunkSize ? chunkSize : (len - bytesWritten); // Write a chunk to UART UART2_write(uart, pValue + bytesWritten, bytesToWrite, NULL); // vTaskDelay(pdMS_TO_TICKS(5)); // Update the bytes written bytesWritten += bytesToWrite; GATT_bm_free(&gattMsg->msg,gattMsg->method); }
Thanks for your support.
Hello Aman,
Thanks for reaching out. Please help me with the following to better understand the issue:
BR,
David.
Here is the following details -
1. simplelink_lowpower_f3_sdk_8_40_00_61
2. Modified DS running as a central+peripheral
3. I haven't check it in debug mode. Please suggest if any modification required at uart level or data handling.
Hello Aman,
I would suggest to go into debug mode and see where the program is crashing so we can get more information about what might be happening. From what you have shared, I don't see yet what could be going on. However, you mentioned you need 9600 baudrate, is this required to transmit data to the PC or to another host device? Could you please show me where you are modifying the baudrate?
BR,
David.