Multiple threads with nRF9160

Hi, 

I have a project with 3 threads running on a nRF9160.  I am using nRF Connect SDK v1.8.0.  Basically I borrowed the code from "mqtt_simple", "location" and "threads".  One of my threads is running "location" with priority of 3.  Another thread is running "mqtt_simple" with priority of 2.  The 3rd thread is reading an accelerometer through SPI with priority of 1.  All 3 threads run correctly when running by itself alone.  Then I have the "location" and "mqtt_simple" thread running together without any problem.  I also have the "location" and the accelerometer thread running together without any problem.  However, when I have the "mqtt_simple" and the accelerometer thread running together, the SPI reading is correct before mqtt client is connected.  But as soon as mqtt client is connected, all SPI readings become wrong. Same problem when I have all 3 threads running together.  Has anyone have problems running multiple threads together, especially with SPI?

Looking at the log messages.  It seems everything is fine upto calling the mqtt broker_init function.  As soon as the IPv4 address is found, then all SPI readings become 0.

Thank you,

Floyd

Parents
  • Hello

    This sounds strange, from what you're describing I would suspect that this isn't caused by the threads, but rather the mqtt and spi libraries not cooperating properly.

    Have you tried probing the SPI pins to see if there is a change in behavior when mqtt is initialized? Maybe turn on more logging from the SPI module?

    How is your SPI code set up? Is it polling or interrupt based?

    Best regards,

    Einar

Reply
  • Hello

    This sounds strange, from what you're describing I would suspect that this isn't caused by the threads, but rather the mqtt and spi libraries not cooperating properly.

    Have you tried probing the SPI pins to see if there is a change in behavior when mqtt is initialized? Maybe turn on more logging from the SPI module?

    How is your SPI code set up? Is it polling or interrupt based?

    Best regards,

    Einar

Children
No Data
Related