【发布时间】:2022-10-06 16:50:49
【问题描述】:
我试图从核心 0 接收的 i2c 设备读取数据,然后将该数据存储到一些全局值中,然后这些值由核心 1 读取,然后打印出来。问题是每当核心 0 尝试访问这些变量时,它都会输出“guru messenger error core 0 panic\'ed (loadprohibited). exception was unhandled\”。 2个核心可以通过什么方式相互通信?
TaskHandle_t Task1;
TaskHandle_t Task2;
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1015 ads;
volatile int16_t adc0, adc1, adc2, adc3;
volatile float volts0, volts1, volts2, volts3;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println(\"Hello!\");
Serial.println(\"Getting single-ended readings from AIN0..3\");
Serial.println(\"ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115\");
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
\"Task1\", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
\"Task2\", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
2, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(500);
if (!ads.begin()) {
Serial.println(\"Failed to initialize ADS.\");
while (1);
}
}
void Task1code( void * pvParameters ){
for(;;){
Serial.print(\"Task1 running on core \");
Serial.println(xPortGetCoreID());
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
volts0 = ads.computeVolts(adc0);
volts1 = ads.computeVolts(adc1);
volts2 = ads.computeVolts(adc2);
volts3 = ads.computeVolts(adc3);
delay(100);
}
}
void Task2code( void * pvParameters ){
delay(500);
Serial.print(\"Task2 running on core \");
Serial.println(xPortGetCoreID());
for(;;){}{
Serial.println(\"-----------------------------------------------------------\");
Serial.print(\"AIN0: \"); Serial.print(adc0); Serial.print(\" \"); Serial.print(volts0); Serial.println(\"V\");
Serial.print(\"AIN1: \"); Serial.print(adc1); Serial.print(\" \"); Serial.print(volts1); Serial.println(\"V\");
Serial.print(\"AIN2: \"); Serial.print(adc2); Serial.print(\" \"); Serial.print(volts2); Serial.println(\"V\");
Serial.print(\"AIN3: \"); Serial.print(adc3); Serial.print(\" \"); Serial.print(volts3); Serial.println(\"V\");
delay(100);
}
}
void loop() {
}
-
ESP Exception Decoder 说崩溃发生在哪里?它的堆栈跟踪是什么?
标签: c++ multithreading arduino esp32 arduino-ide