cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO read correct data

SGian.1
Senior

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

2 REPLIES 2
Uwe Bonnes
Principal III

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.

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