0
\$\begingroup\$

I have a circuit which has:

  • STM32F446RET6 MCU
  • 2 IMUs
  • 1 Barometer Sensor
  • 1 Micro SD Card Module
  • 1 External Flash Chip
  • 1 GPS Module
  • 1 LoRa Module

And when I try to use all of them in my code I can only achieve 6 to 8 while cycles in a second which means 6 to 8 sensor readings per second which is really slow considering I need to integrate gyro and accelerometer datas.

How can I achieve more sensor readings in a while loop? I heard that interrupt usage can help but I'm not sure. Can interrupt help in my situation? (Both IMUs have interrupt outputs.)

\$\endgroup\$
4
  • \$\begingroup\$ it's like a group of people walking in a circle ... the speed is determined by the slowest person \$\endgroup\$
    – jsotola
    Aug 7, 2021 at 23:16
  • 3
    \$\begingroup\$ Sorry but we don't know what your code does and where does it spend the time so we don't know how to make it faster either. \$\endgroup\$
    – Justme
    Aug 8, 2021 at 0:14
  • \$\begingroup\$ Sorry, I forgot to add my question about interrupts. Can using interrupts solve my problem? I edited my first message by the way. \$\endgroup\$ Aug 8, 2021 at 0:21
  • \$\begingroup\$ Are you polling them sequentially and only moving to the next device after you get a response? Just think about how you would do it in real life if you were going door to door asking people for info but it took them different times to get back to you. Microcontrollers aren't any different. Would you have them call you when ready? Maybe you prefer to ask if they are ready? Would you stand around waiting if they weren't ready? Or maybe you call the ones who respond faster a lot more often than the slower ones. \$\endgroup\$
    – DKNguyen
    Aug 8, 2021 at 1:07

1 Answer 1

0
\$\begingroup\$

Don't do them in a while loop is how you read them faster. You microcontroller has many features that allow communications to be handled in the hardware peripherals instead of by your software which has only one thread of execution (assuming no RTOS is present). I assume your sensors are some mix of SPI, I2C and UART. Do some research on how to setup these hardware peripherals to use interrupts and DMA, there are plenty of good examples out there.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.