Skip to main content
TrixCZE
Associate
February 20, 2021
Question

How to read data from pins? STM32F4

  • February 20, 2021
  • 2 replies
  • 2368 views

Hello everyone,

I would like to know how to read data from pin on STM32F4. I have a small project where I am blinking led (it's running throw Arduino board) and I would like to see throw STM32F4 when it's on and when it isn't. How should I setup pin? GPIO_INPUT or GPIO_ANALOG? I am new to programming so I am sorry for my question. I would like to create something like a simple logic analyzer so I could see in debug the logic of led. I would like to have something whats on the picture I attached. 0693W000007Z0RKQA0.pngThanks for any help.

    This topic has been closed for replies.

    2 replies

    Simon V.
    ST Employee
    May 24, 2021

    Hello TrixCZE,

    Reading GPIO state can be achieved reading the IDR register input data register of the GPIO port your application is using.

    You can refer to AN4899 - STM32 GPIO configuration for hardware settings and low-power consumption

    Regards,

    Simon

    To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
    BParh.1
    Senior III
    May 24, 2021

    What do you mean by reading pin here and who is reading?

    If you meant for CPU to read the register value associated with the GPIO port, in this case you would need to setup your pin as output as you need it to drive the external LED. Then consult the data sheet to know the register address of the GPIO and then you can read it in your code. To toggle the LED, you simply toggle 1 and 0 to the register. Hope it helps