Skip to main content
SGian.1
Associate III
Apr 26, 2024 6:53 AM UTC
Question

GPIO read correct data

Hi there !

I start a project with STM32G031k8. This board i'm gonna make is  a RS485 slave on the pin 4-5-6-7 of GPIOA i put a dipswitch with pullup resistor , and i read in this way:

uint16_t Add = ( 0x00F0 & GPIOA->IDR)>> 4 ; 

right now my add is 5. My problem is sometime i don't read 5 but 1 ,  and if i don't turn off the power and turn on again i'm still to read 1 . 

I hope some one can help me to understand where i make my mistake 

Thank you

Sergio

This topic has been closed for replies.

2 replies

Uwe Bonnes
Chief
Apr 26, 2024 9:14 AM UTC

Carefully check your setup. Read voltage on PA4-7 with a meter. If the voltages are as expected, post what you read from GPIOA with a debugger  like "p /x *GPIOA". If the meter disagrees with your expectation, carefully check your code that PA5-7 are not used by any other code. Again,  interpreting "p /x *GPIOA" against the reference manual can help.

SGian.1
SGian.1Author
Associate III
Apr 26, 2024 9:21 AM UTC

i did and the voltage is right . The strange thingh is afther a while i use a debug for try my function happend and is really soo strange. For sure this pin are not use for did nothingh else and i made one mistake the resistor are not pul up but pull down. I try to check the manual and see if i made somo mistake .

Thank you