Page 1 of 1

STM32F103C8T6 blue pill INPUT pullup issue

Posted: Sat Aug 12, 2023 9:18 am
by asking
Hi,

On PA0, PA1 and PA2 are define as input with Pull up enabled. as per below code, but when i push the button LED on PC13 Turns off instead of being turned on.

what could be wrong ?

Code: Select all

bool START = 0, STOP = 0, RESET1 = 0;


void buttons()
{
  START = digitalRead(PA0); //START BUTTON
  STOP = digitalRead(PA1); //STOP BUTTON
  RESET1 = digitalRead(PA2); // RESET BUTTON
}


void setup(void) {
  pinMode(PC13, OUTPUT);
  pinMode(PA0, INPUT_PULLUP);
  pinMode(PA1, INPUT_PULLUP);
  pinMode(PA2, INPUT_PULLUP);
}

void loop(void) {
buttons();

if(STOP == 0)
{
  digitalWrite(PC13, HIGH);
}
else
  digitalWrite(PC13, LOW);
}



Re: STM32F103C8T6 blue pill INPUT pullup issue

Posted: Sat Aug 12, 2023 11:43 pm
by GonzoG
1. If you're using pullups, then with button pressed you get 0, and not pressed you get 1.
2. PC12-PC15 pins cannot source current, but they can sink, so pin provides GND to LED. 0 = on, 1= off

Re: STM32F103C8T6 blue pill INPUT pullup issue

Posted: Sun Aug 13, 2023 6:45 am
by ag123
on blue pill, that led is 'active low', i.e.
digitalWrite(LED_BUILTIN, 0) is on
and like @GonzoG mentions
input pull up, means the input is 'inverted', i.e. it is 1 unless 'shorted to gnd' (use a resistor to do that, e.g. like 300-1k ohms)