Embedded

PB0 Functions
| Function | Description |
|---|---|
| GPIO Input | Read a push button or switch |
| GPIO Output | Control an LED, relay, or buzzer |
| ADC Input | Read analog signals from sensors (if enabled on this pin) |
| EXTI | External interrupt input |
| Timer / Alternate Function | PWM generation or timer input/output (depending on the timer mapping) |
Common Uses
1. LED Control
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET); // LED ON HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); // LED OFF
2. Push Button
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0) == GPIO_PIN_SET) { // Button is pressed }
3. Analog Sensor
You can connect:
- Potentiometer
- LM35 Temperature Sensor
- LDR
- Soil Moisture Sensor (analog output)
to PB0 if it is configured as an ADC input.
4. PWM Output
PB0 can be configured as a timer output to:
- Control LED brightness
- Drive a servo motor
- Control DC motor speed
Pin Type
PB0 │ ├── GPIO ├── ADC ├── EXTI └── Timer (Alternate Function)
In STM32CubeMX
Click PB0 and you can configure it as:
- GPIO_Input
- GPIO_Output
- ADC
- Timer/PWM (if supported)
- Other alternate functions supported by the MCU
AGND Pin
AGND = Analog Ground
Purpose
AGND provides a clean, low-noise ground for analog circuits.
Devices connected to AGND
- 🌡️ LM35 Temperature Sensor
- 🌡️ TMP36
- 💧 Soil Moisture Sensor (Analog Output)
- 🔆 LDR (with voltage divider)
- 🔘 Potentiometer
- 🎤 Analog Microphone
- 📈 Any sensor connected to an ADC pin
Example Circuit
STM32 3.3V ──────────────┐ │ Potentiometer │ PA0 (ADC) │ AGND ──────────────┘
Here:
- 3.3V supplies the sensor.
- PA0 reads the analog voltage.
- AGND is the reference ground.PB13 means:
- P = Port
- B = Port B
- 13 = Pin number 13
So PB13 = Port B, Pin 13.
On the STM32C031C6, PB13 is a general-purpose I/O (GPIO) pin that can also support alternate functions depending on the microcontroller's pin mapping.
PB13 Functions
Function Use GPIO Input Read a button or switch GPIO Output Control an LED, relay, or buzzer EXTI External interrupt Alternate Function Timer, SPI, or other peripheral (depending on the MCU configuration) Example 1: LED
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET); // LED ON HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); // LED OFFExample 2: Button
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_13) == GPIO_PIN_SET) { // Button pressed }Typical Uses
- ✅ LED control
- ✅ Push button input
- ✅ External interrupt (EXTI)
- ✅ PWM output (if configured as a timer channel)
- ✅ SPI signal (if mapped to SPI through an alternate function)
GPIO vs Alternate Function
PB13 │ ├── GPIO Output → LED ├── GPIO Input → Button ├── EXTI → Interrupt └── Alternate Function → SPI / Timer (if supported)
Comments