cancel
Showing results for 
Search instead for 
Did you mean: 

How to fast read GPIO?

Yash
Associate II

Hello,

i'm reading GPIO using internal instruction of GPIO_ReadPin function like "(GPIOC->IDR & GPIO_PIN_1)?1:0;" but i didn't get actual speed. So is there any alternative way to read GPIO fast ?

Regards,

Yash

4 REPLIES 4
Uwe Bonnes
Principal III

What chip family? What speed do you reach and what CPU speed? What code? Code running in flash or ram?

KnarfB
Principal III

GPIO access is usually much slower than MCU clock, even at register or assembler level access. Also depends on chip series.

TDK
Guru

In any case, there is no alternative to reading GPIO pin states other than reading IDR. You can use DMA, but it uses it the same access and will have the same drawbacks.

You could do something exotic like make it an SPI pin and read it indirectly that way, but not really recommended.

If you feel a post has answered your question, please click "Accept as Solution".
S.Ma
Principal

Checklist:

Do you need to read the pin fast for how long?

What is the maximum scan frequency?

Will the processor have enough time to keep up processing the data?

Is interrupt resilient?

Options with tradeoffs are

Dma read pin to memory ram

Timer capture to take a timestamp wheb signal toggles

Use exti to get notified or event trigger of dma on rise or fall edge....