STM32F103C8T6 blue pill INPUT pullup issue

Post here first, or if you can't find a relevant section!
Post Reply
asking
Posts: 16
Joined: Mon May 29, 2023 1:15 pm

STM32F103C8T6 blue pill INPUT pullup issue

Post 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);
}


GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: STM32F103C8T6 blue pill INPUT pullup issue

Post 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
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32F103C8T6 blue pill INPUT pullup issue

Post 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)
Post Reply

Return to “General discussion”