Core Panic with Bluetooth + freeRTOS
Posted: Tue Feb 01, 2022 5:37 am
- Hi all, I have a simple program to measure an external ADC via SPI with the ESP32 and I am trying to send the raw data received over bluetooth to my PC. I have implemented freeRTOS within the arduino IDE and when using the Serial port the code works without issues. When I attempt to do the same using Bluetooth Serial the ESP32 resets continuously in panic and I get: Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1). I have tried my best to debug it and explore similar threads on the internet but I can't really figure out the issue. Below is my code and the snippet of the error message (I haven't figured out how to decode the backtrace yet). Any advice would be extremely welcome, thanks in advance!
- //
- #include "esp_system.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/timers.h"
- #include <SPI.h>
- #include <SoftwareSerial.h>
- #include <BluetoothSerial.h>
- #include <ads1262.h>
- #define PGA 32 // Programmable Gain = 32
- #define VREF 2.50 // Internal reference of 2.5V
- #define BUFF_SIZE 32
- #define BYTE_LEN 4 // Number of bytes for 32 bit int
- ads1262 ADS; // ADS class
- BluetoothSerial SerialBT;
- int32_t val1;
- int32_t val2;
- int32_t val3;
- int32_t val4;
- int32_t val5;
- int32_t data1;
- int32_t data2;
- int32_t data3;
- int32_t data4;
- int32_t timeData;
- int32_t t_start;
- int32_t t_finish;
- volatile char *data_struct;
- volatile char buff_array[6];
- volatile long data_array[4];
- volatile signed long counts;
- volatile int isDataReady = 0;
- TaskHandle_t TaskGetData;
- TaskHandle_t TasksendPC;
- QueueHandle_t Queue1;
- QueueHandle_t Queue2;
- QueueHandle_t Queue3;
- QueueHandle_t Queue4;
- QueueHandle_t QueueT;
- //SemaphoreHandle_t semaphore;
- void setup()
- {
- portDISABLE_INTERRUPTS();
- // initalize the data ready and chip select pins:
- pinMode(ADS1262_DRDY_PIN, INPUT); // Data ready input line
- pinMode(ADS1262_CS_PIN, OUTPUT); // Chip enable output line
- pinMode(ADS1262_START_PIN, OUTPUT); // Start
- pinMode(ADS1262_PWDN_PIN, OUTPUT); // Power down output
- attachInterrupt(digitalPinToInterrupt(ADS1262_DRDY_PIN), awaitDRDY, FALLING);
- SerialBT.begin("PLAKA PLATES");
- // Serial.begin(500000); // Max Baud Rate
- ADS.ads1262_Init(); // Initialise ADS1262
- Queue1 = xQueueCreate(500, sizeof(int32_t));
- Queue2 = xQueueCreate(500, sizeof(int32_t));
- Queue3 = xQueueCreate(500, sizeof(int32_t));
- Queue4 = xQueueCreate(500, sizeof(int32_t));
- QueueT = xQueueCreate(500, sizeof(int32_t));
- setCpuFrequencyMhz(240);
- xTaskCreatePinnedToCore(loopGet, "TaskGetData", 4096, NULL, 3, &TaskGetData, 1); // 0
- xTaskCreatePinnedToCore(loopSend, "TasksendPC", 4096, NULL, 3, &TasksendPC, 1); // 1
- portENABLE_INTERRUPTS();
- }
- void loop()
- {
- vTaskDelete (NULL);
- }
- void loopGet(void *parameter)
- {
- for (;;) {
- t_start = micros(); // micros()
- // Cycle through differential channels
- val1 = read_channel(0x01);
- val2 = read_channel(0x23);
- val3 = read_channel(0x45);
- val4 = read_channel(0x67);
- val5 = read_channel(0x01); // Dummy read to not affect 4th load cell reading
- xQueueSend(Queue1, &val1, portMAX_DELAY);
- xQueueSend(Queue2, &val2, portMAX_DELAY);
- xQueueSend(Queue3, &val3, portMAX_DELAY);
- xQueueSend(Queue4, &val4, portMAX_DELAY);
- t_finish = micros() - t_start;
- xQueueSend(QueueT, &t_finish, portMAX_DELAY);
- }
- }
- void loopSend(void *parameter)
- {
- for (;;) {
- xQueueReceive(Queue1, &data1, portMAX_DELAY);
- xQueueReceive(Queue2, &data2, portMAX_DELAY);
- xQueueReceive(Queue3, &data3, portMAX_DELAY);
- xQueueReceive(Queue4, &data4, portMAX_DELAY);
- xQueueReceive(QueueT, &timeData, portMAX_DELAY);
- // Serial Port Debug
- // printf("%i,%i,%i,%i,%i\n", data1, data2, data3, data4, timeData);
- // Send binary to Bluetooth Serial Port
- SerialBT.write((byte*)&data1, BYTE_LEN);
- SerialBT.write((byte*)&data2, BYTE_LEN);
- SerialBT.write((byte*)&data3, BYTE_LEN);
- SerialBT.write((byte*)&data4, BYTE_LEN);
- SerialBT.write((byte*)&timeData, BYTE_LEN);
- SerialBT.write('\n');
- }
- }
- void awaitDRDY() { // IRAM_ATTR
- isDataReady = 1;
- // xSemaphoreGive(semaphore);
- }
- // Read adc binary data
- int32_t read_channel(char channel)
- {
- // Channel multiplexer channel
- ADS.ads1262_Reg_Write(INPMUX, channel);
- // Wait until ADC is ready for conversion // while (digitalRead(ADS1262_DRDY_PIN) != LOW){
- isDataReady = 0;
- while (isDataReady != 1) {}
- // xSemaphoreTake(semaphore, portMAX_DELAY); // Faster ISR response to DRDY signal
- // Dump Binary Data
- data_struct = ADS.ads1262_Read_Data();
- for (int i = 1; i < 5; ++i)
- {
- buff_array[i] = *(data_struct + i);
- data_array[i] = (unsigned char)buff_array[i];
- }
- counts = (signed long) (((unsigned long)data_array[0]<<24) | ((unsigned long)data_array[1]<<16) | (data_array[2]<<8) | data_array[3]);
- return counts;
- }
- Rebooting...
- ets Jul 29 2019 12:21:46
- rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
- configsip: 0, SPIWP:0xee
- clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
- mode:DIO, clock div:1
- load:0x3fff0018,len:4
- load:0x3fff001c,len:1044
- load:0x40078000,len:10124
- load:0x40080400,len:5856
- entry 0x400806a8
- Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
- Core 1 register dump:
- PC : 0x40092824 PS : 0x00060b34 A0 : 0x80091a3b A1 : 0x3ffc7490
- A2 : 0x3ffbbca4 A3 : 0x3ffc7720 A4 : 0x00000001 A5 : 0x00000001
- A6 : 0x00060b23 A7 : 0x00000000 A8 : 0x3ffc7720 A9 : 0x3ffc7720
- A10 : 0x00000018 A11 : 0x00000018 A12 : 0x00000001 A13 : 0x00000001
- A14 : 0x00060b23 A15 : 0x00000000 SAR : 0x0000001d EXCCAUSE: 0x00000006
- EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
- ELF file SHA256: 0000000000000000
- Backtrace: 0x40092824:0x3ffc7490 0x40091a38:0x3ffc74b0 0x4008fcef:0x3ffc74d0 0x400e2fbb:0x3ffc7510 0x4015a1df:0x3ffc7530 0x400e354f:0x3ffc7570 0x400d23aa:0x3ffc7590 0x400d1e3e:0x3ffc75d0 0x400d13ba:0x3ffc7610 0x400d3332:0x3ffc7650 0x4008ff1a:0x3ffc7670
- Core 0 register dump:
- PC : 0x40090f1e PS : 0x00060334 A0 : 0x80092079 A1 : 0x3ffcbb10
- A2 : 0x3ffbed5c A3 : 0x0000cdcd A4 : 0xb33fffff A5 : 0x00000001
- A6 : 0x00060123 A7 : 0x0000abab A8 : 0x0000abab A9 : 0x3ffcbc50
- A10 : 0x3ffae704 A11 : 0x00000002 A12 : 0x00060320 A13 : 0x3ffcbcf8
- A14 : 0x00000006 A15 : 0x00000000 SAR : 0x00000000 EXCCAUSE: 0x00000006
- EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
- ELF file SHA256: 0000000000000000
- Backtrace: 0x40090f1e:0x3ffcbb10 0x40092076:0x3ffcbb40 0x4008fc57:0x3ffcbb60 0x40086517:0x3ffcbba0 0x400865ed:0x3ffcbbd0 0x40172691:0x3ffcbbf0 0x40155636:0x3ffcbc10 0x401556e5:0x3ffcbc50 0x400814e6:0x3ffcbc80 0x40159676:0x3ffcbca0 0x40159744:0x3ffcbcd0 0x40159d28:0x3ffcbcf0 0x4008ff1a:0x3ffcbd20