Klaus_K:
You need to learn about the core and system architecture. There are a few key concepts you need to understand.
You are correct, I need to learn more, that's why I'm posting here. A helpful and very active community we have here, and some have knowledge of what I am looking to learn.
Juraj:
wrong forum?
Please direct me to the correct forum I should try.
gfvalvo:
It stands to reason that we'd need to see your code.
Of course you need to see the code, but it's quite long (1500+) lines and uses custom libraries, which is why I didn't post it.
Here is a condensed pseudo code version which should explain the problem:
void setup()
{
initialize all sensors
initialize fona
define fona task
}
void fona task()
{
// code runs on core0
while (true)
{
if (SMS received)
{
SMShandler()
}
}
}
void loop()
{
// running on core1
read data from sensors
if (sensor failed)
{
sendSMSerror()
}
}
void SMShandler()
{
get & parse SMS
if (SMS command = stat)
{
sendSMSstatus()
}
else if (SMS command = set)
{
changeSettings()
}
}
void sendSMSstatus()
{
create statusMsg
sendSMS(statusMsg)
}
void changeSettings()
{
create responseMsg
sendSMS(responseMsg)
}
void sendSMSerror()
{
create errorMSG
sendSMS(errorMSG)
}
void sendSMS(MSG)
{
actually send the MSG via fona device
}
So the fona task runs on core0. It looks for a new SMS msg and processes it, then sends a reply via SMS
The code in loop(), running on core1, when it detects a problem with a sensor, wants to send a SMS via the sensSMSerror() function. Calling the sendSMSerror() function from core1 fails. Why is that?
If I modify the above code to this:
boolean sensorError = false
void setup()
{
initialize all sensors
initialize fona
define fona task
}
void fona task()
{
// code runs on core0
while (true)
{
if (SMS received)
{
SMShandler()
}
if (sensorError = true)
{
sendSMSerror()
}
}
}
void loop()
{
// running on core1
read data from sensors
if (sensor failed)
{
sensorError = true
}
}
void SMShandler()
{
get & parse SMS
if (SMS command = stat)
{
sendSMSstatus()
}
else if (SMS command = set)
{
changeSettings()
}
}
void sendSMSstatus()
{
create statusMsg
sendSMS(statusMsg)
}
void changeSettings()
{
create responseMsg
sendSMS(responseMsg)
}
void sendSMSerror()
{
create errorMSG
sendSMS(errorMSG)
}
void sendSMS(MSG)
{
actually send the MSG via fona device
}
Yet, when I make those changes, looking for a flag in the fona task, running on core0, then calling the sendSMSerror() function, the code works and the SMS is sent.
What I am failing to understand is why when sendSMSerror() is called from core1, it doesn't work. When sendSMSerror() is called from core0, it works. I have two loops, one running on each core, but the rest of the code, like sendSMSerror(), isn't assigned to any core, so isn't it available to both cores?
Clearly, there is something about the dual core architecture that I don't understand or know...
Thanks for any help,
Randy