[GianniDPC – Sun Jun 25, 2017 1:26 pm] –
[Rick Kimball – Sun Jun 25, 2017 12:40 pm] –
[GianniDPC – Sat Jun 24, 2017 4:31 pm] –
One more question, I defined the ADC on port A0 in my code, and it works fine when I connect a voltage to A0. But if I plug my wire into A1 for example it also shows me that ADC value even when I didn’t tell my code to do that. Is this normal behaviour?
I don’t understand the question. It “shows you the ADC value” what does that mean? Can you post the code you are using?
Well the code is the same as in my first post. But what I mean is that I defined A0 as my analog pin in the code and I get my output from the serial monitor as expected, which is 4095 when using a 12-bit resolution.
But when I disconnect the 5V from A0 and connect it to A1 the serial monitor still shows me the same result so 4095. I don’t expect this as I defined A0 as my analog pin in the code and not A1.
I’m not sure I follow. If you are looking at pin A1, but your input is on pin A0, then if A1 is not tied high or low, it may well drift up towards the level of the adjacent pin(s).
I would get a couple of 100K linear pits, strap them between 5V and gnd, and point the wipers at the A0 and A1 pins, and slowly rotate the wiper from the gnd end towards the 5V end.
You should see the values on the analog pins follow, up till the reach a maximum when the output of the voltage divider formed by the 100k pot hits around 3.3V .. what happens next, if you move the wiper any further, rather depends on how robust the STM32F103 pins you have chosen are.
If they are 5V tolerant (remember the STM32F103 is a 3.3V device, not a 5V one), then they will stay at the maximum value, and when you rotate the wiper back towards gnd, the value will start to drop again. If they are not 5V tolerant, there will be a lot of heat, perhaps some smoke, and you will earn yourself an honorary membership of our well attended magic smoke club.
Better still, check the spec. of pins in the STM32F103 datasheet first to be sure they will suffer such misuse.
EDIT: Thanks Rick, I must admit I was too lazy to check the spec of the analog pins.