if i set a pin for INPUT_PULLDOWN pinMode(PIN, INPUT_PULLDOWN)
souldnt i read 3.3 volts? beacause i am reading just some millivolt
i just want to check for HIGH and LOW state , the device its a deep switch with 3 pins , that returns 5v to each ,or 0v depenging what switch is on
i saw in some old sketches for arduino uno that they use Input pull down , wich the pin of arduino that reads the state normal HIgh
am i missing something??
GPIO_InitStruct.Pin = my_pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(my_pin_Port, &GPIO_InitStruct);
https://github.com/rogerclarkmelbourne/ … pp#L58-L60
It may be possible to enable PULL DOWN and ANALOG at the same time, but the core does not support that mode
Check the STM32F103 manual and see if such a mode exists and how to enable it
Note. The pulldown resistor is highly variable, between about 30k and 50k, so I don’t think its a good idea to try to use it with analog input you will form an unknown voltage divider between your external impedance and an unknown (30 – 50k ) internal resistance
void loop() {
pinMode(PA0,INPUT_PULLDOWN);
Serial.println("Down "+String(analogRead(PA0)));
pinMode(PA0,INPUT_PULLUP);
Serial.println("Up "+String(analogRead(PA0)));
}
Interesting.
I always presumed that the pin had to be in analog input mode for the ADC to work.
pinMode(PA0, INPUT_PULLUP); // activates the internal pull-up resistor
uint8_t val = digitalRead(PA0); // will give you high, "1", true[alexandros – Tue Nov 28, 2017 9:30 pm] –
i just want to check for HIGH and LOW state
I cannot recognize any hint to read analog, but I might be wrong.
[stevestrong – Wed Nov 29, 2017 9:58 am] –[alexandros – Tue Nov 28, 2017 9:30 pm] –
i just want to check for HIGH and LOW stateI cannot recognize any hint to read analog, but I might be wrong.
True.
They mentioned 3.3V and millivolts so I assumed they were reading the voltage not logic level..
But I am probably wrong
Either way, the internal pull-up is very weak and not that much use
[RogerClark – Wed Nov 29, 2017 9:36 am] – I always presumed that the pin had to be in analog input mode for the ADC to work
I just did a bunch of experiments, and it’s kind of the other way around. In INPUT, INPUT_PULLUP and INPUT_PULLDOWN modes, both analogRead() and digitalRead() work. In INPUT_ANALOG mode, analogRead() works but digitalRead() returns 0 even with the pin connected directly to 3.3V.
I just read 100,000 samples while connected to an old analog joystick (with 10K pulldown, not moving handle) and got:
- INPUT: avg 551.2; std dev 3.94
- INPUT_ANALOG: avg 550.9; std dev 3.96
So no difference.
Maybe there is no difference in analog performance between the two modes, but we save some power by using INPUT_ANALOG instead of INPUT? I’ve seen online advice to put stm32f pins in analog mode when not in use to conserve power.
[arpruss – Wed Nov 29, 2017 4:27 pm] –[RogerClark – Wed Nov 29, 2017 9:36 am] – I always presumed that the pin had to be in analog input mode for the ADC to workI just did a bunch of experiments, and it’s kind of the other way around. In INPUT, INPUT_PULLUP and INPUT_PULLDOWN modes, both analogRead() and digitalRead() work. In INPUT_ANALOG mode, analogRead() works but digitalRead() returns 0 even with the pin connected directly to 3.3V.
I just read 100,000 samples while connected to an old analog joystick (with 10K pulldown, not moving handle) and got:
- INPUT: avg 551.2; std dev 3.94
- INPUT_ANALOG: avg 550.9; std dev 3.96
So no difference.
Maybe there is no difference in analog performance between the two modes, but we save some power by using INPUT_ANALOG instead of INPUT? I’ve seen online advice to put stm32f pins in analog mode when not in use to conserve power.
Very interesting.
Perhaps the INPUT ANALOG mode detaches the connection to the digital input silicon to take load off the analog input and give better frequency response. I think a test would need to be done using the PigOSxope code fed with a square wave, and observing the rise time etc
pinMode(puerta1, INPUT_PULLDOWN);
work for me, put 0V to pin if input float, if put 5V ( pin 5v tolerant ) read 5v… it is ok
work in pin B5 and B6, and dont work in A11-A12-A15-B3-B4… this pins always 3.3 or 0V, it is rare, or chinese seller send to me bad bluepill or i dont know…
this pins work for you??
yeah. the datasheet is quite clear on that: the only difference is the de-activation of the input buffer under the analog mode.
[ramgc – Fri Dec 01, 2017 11:50 am] –
work in pin B5 and B6, and dont work in A11-A12-A15-B3-B4… this pins always 3.3 or 0V, it is rare, or chinese seller send to me bad bluepill or i dont know…
Those pins are rsserved for Usb and SWD interface.
Search the forum for pb4.
[stevestrong – Fri Dec 01, 2017 2:23 pm] –[ramgc – Fri Dec 01, 2017 11:50 am] –
work in pin B5 and B6, and dont work in A11-A12-A15-B3-B4… this pins always 3.3 or 0V, it is rare, or chinese seller send to me bad bluepill or i dont know…Those pins are rsserved for Usb and SWD interface.
Search the forum for pb4.
Thanks, now all work.
If disable debugs, later dont recognize stlink and i have to erase chip with program st with hardware reset, but almost work
THANKS!!
almost surely, except when it doesn’t.
a similar trap exists on older the older luminary chips: if your code executes so fast that it disables the debug pins before the connection is made, you will never be able to debug the chip. A recent example is here: https://dannyelectronics.wordpress.com/ … -lock-out/
luminary’s “work-around” is to insert a large delay routine at the very beginning of user space to allow the debugger to kick in before doing anything, so if your code isn’t working perfectly, you can still program it.
Put the jumpers on Boot0 to High
Or
use connect under reset
[dannyf – Sat Dec 02, 2017 1:22 pm] –
luminary’s “work-around” is to insert a large delay routine at the very beginning of user space to allow the debugger to kick in before doing anything, so if your code isn’t working perfectly, you can still program it.
shouldn’t be a good idea to put this delay “before” the setup?
in arduino it is something like this:
void main() {
init();
setup();
while (1)
loop();
}
The difference in time with be micoseconds


