Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transitioning AD7124 Library from Polling to Interrupt Mode on STM32 #2309

Open
AmirhoseinAskari opened this issue Sep 25, 2024 · 1 comment

Comments

@AmirhoseinAskari
Copy link

Hi,

I’m using the AD7124 driver from this repository with an STM32 MCU. My setup is as follows:

MCU Clock Frequency: 2 MHz
SPI Speed: 1 MHz
Current Communication Status: Working correctly with AD7124.

Problem:
The current implementation of the driver uses a polling mechanism (ad7124_wait_for_spi_ready and ad7124_wait_for_conv_ready functions), which causes significant delays in my main application loop. Specifically, I’m encountering a delay of approximately 800 ms, which negatively impacts the performance of my system.

I would like to eliminate this delay by moving from polling to an interrupt-based approach.

Challenge:
The RDY pin (used to indicate data ready) is multiplexed with the DOUT pin on the AD7124. This makes it unclear how to set up an efficient interrupt-based solution since RDY and DOUT share the same pin.

Request:
1- Is there a recommended approach for using interrupts with the AD7124 when RDY and DOUT are on the same pin?
2- Has anyone else faced and solved this challenge when trying to avoid polling delays?
3- Any guidance or alternative methods for handling this scenario would be highly appreciated.

Thank you in advance for your help and support!

@buha
Copy link
Contributor

buha commented Oct 1, 2024

Hi,
I've looked at the driver code and indeed it's based on polling some status bits.

For the moment, what you could do is provide a small timeout for the ad7124_wait_for_spi_ready() and ad7124_wait_for_conv_ready() functions when you call them and make sure to call them often in your application loop and let the loop do the other things it needs to do in between calls. But you'll likely need to implement a small state machine to keep track of where you're at in the conversion.

The other alternative is to set up a GPIO interrupt on the RDY pin (using no-OS GPIO interrupt controller) although being multiplexed, I don't know how well it will work, unless you have a separate pin that you configure as an input and electrically hook it up to the DOUT.

1st method seems much easier for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants