Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Nucleo 401RE Controlled LED with Button Input

View and Edit Project In Cirkit DesignerImage of Nucleo 401RE Controlled LED with Button Input

Circuit Documentation

Summary

This document provides a detailed description of a simple circuit involving an STM32 Nucleo-64 development board (Nucleo 401RE), a red LED, and a resistor. The circuit is designed to control the LED using the microcontroller, with the resistor limiting the current through the LED.

Component List

Nucleo 401RE

LED: Two Pin (red)

Resistor

Wiring Details

Nucleo 401RE

LED: Two Pin (red)

Resistor

Code Documentation

sketch.ino

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

gpio.h

#ifndef __GPIO_H
#define __GPIO_H
#include "stdint.h"
void init_gpio(void);
void write_pin(int);
int read_pin(void);
#endif

test1.cpp

#include "gpio.h"
int main()
{
  init_gpio();
  while(1)
  {
    write_pin(read_pin());
    for(int i = 0; i<100; i++);
  }
}

gpio.cpp

#include "gpio.h"
#include "stm32f446xx.h"
void init_gpio(void)
{
  //enable PORT A for LED output
  RCC->AHB1ENR |= 1<<0;
  //Pin 1 output mode and speed for LED 1
  GPIOA->MODER |= 1<<2;
  GPIOA-> OSPEEDR |= 3<<2;

  //enable PORT C for button input
  RCC->AHB1ENR |= 1<<2;
  //Pin 13 input mode for the mounted button on PORT C Pin 13
  GPIOC->MODER &= ~(3<<26);
}

//reading the input from button, default = 1, pressed = 0
int read_pin(void){
  int value = 1;
  if (GPIOC->IDR & 1<<13){
    value = 0;
  }
  return value;
}

//turn led on based on button
void write_pin(int value)
{
  if (value == 1){
    //if pressed, LED 1 on
    GPIOA->BSRR |= 1<<1;
  }
  if (value == 0){
    //if not pressed, LED 1 off
    GPIOA->BSRR |= 1<<1<<16;
  }
}

This documentation provides a comprehensive overview of the circuit, including the components used, their connections, and the code running on the microcontroller.