UART to SPP Bridge - ESP reboots whenever esp_spp_write() is called
Posted: Fri Jul 17, 2020 3:44 pm
Hi All, first post ever so hopefully I do this right
I'm trying to do something very similar to this post (https://esp32.com/viewtopic.php?t=5499), and likely experiencing a similar problem, but I just can't seem to get around it.
I'm trying to use the esp_spp_write() function to send data received from UART_NUM_1. I've essentially pulled together the code from the "bt_spp_acceptor" and "uart_echo" examples. I've used xTaskCreate to create a task that runs whenever data is received on the uart,
and in the task uart_rx_task(), I attempt to call the esp_spp_write() function:
In this case I've dumbed it down to just sending a fixed string "CHAR RXED", I'm not even trying to write the data from the buffer yet, but whenever I sent a character through the UART to trigger the uart_rx_task(), the esp32 reboots. The unit does not reboot when I commenting out the esp_spp_write() line, so I think that the uart_rx_task() itself is working ok.
I should mention that I'm setting the send handle for the bluetooth "sppSendHandle" in the esp_spp_cb() callback function when the "ESP_SPP_SRV_OPEN_EVT" occurs.
I thought this might have to do with the way I'm calling the esp_spp_write() function outside of the esp_spp_cb() function or my use of the send handle, but I've successfully sent data every 1/2 second using a timer like so:
So I'm really not sure what I'm doing wrong. Any help to point me in the right direction would be much appreciated!
I'm trying to do something very similar to this post (https://esp32.com/viewtopic.php?t=5499), and likely experiencing a similar problem, but I just can't seem to get around it.
I'm trying to use the esp_spp_write() function to send data received from UART_NUM_1. I've essentially pulled together the code from the "bt_spp_acceptor" and "uart_echo" examples. I've used xTaskCreate to create a task that runs whenever data is received on the uart,
- xTaskCreate(uart_rx_task, "my_uart_rx_task", 1024*2, NULL, configMAX_PRIORITIES, NULL);
- static void uart_rx_task() {
- ...
- while (1) {
- const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_BUF_SIZE, 10 / portTICK_RATE_MS);
- if (rxBytes > 0) {
- data[rxBytes] = 0;
- if (spp_param->write.cong == 0) {
- #define RX_STRING_LEN 10
- uint8_t RX_STRING[RX_STRING_LEN] = "CHAR RXED";
- esp_spp_write(sppSendHandle, RX_STRING_LEN, RX_STRING);
- }
- }
- }
- free(data);
- }
I should mention that I'm setting the send handle for the bluetooth "sppSendHandle" in the esp_spp_cb() callback function when the "ESP_SPP_SRV_OPEN_EVT" occurs.
- static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
- {
- switch (event) {
- ...
- case ESP_SPP_SRV_OPEN_EVT:
- sppSendHandle = param->srv_open.handle;
- break;
- ...
- }
- }
- static void periodic_timer_callback(void* arg) {
- #define TEST_STRING_LEN 5
- uint8_t TEST_STRING[TEST_STRING_LEN] = "TEST";
- esp_spp_write(sppSendHandle, TEST_STRING_LEN, TEST_STRING);
- }