Struggling to set pins to high on NucleoF411RE
EDIT: Solved. It seems to just be that one pin that isn’t working. I tried a couple other ones and they work fine.
Hello, sorry if this is a silly question, but I'm pretty new to all of this. I've recently picked up Israel Gbati's Bare-Metal Embedded C Programming. It gives a step-by-step walkthrough on how to turn on an LED using pin D12/PA5, but I'm struggling to connect to any of the other pins.
I've been trying to connect my LED to pin D0/PA3. My code is below.
#define PERIPH_BASE (0x40000000UL)
#define AHB1PERIPH_OFFSET (0x00020000UL)
#define AHB1PERIPH_BASE (PERIPH_BASE + AHB1PERIPH_OFFSET)
#define GPIOA_OFFSET (0x0000UL)
#define GPIOA_BASE (AHB1PERIPH_BASE + GPIOA_OFFSET)
#define RCC_OFFSET (0x3800UL)
#define RCC_BASE (AHB1PERIPH_BASE + RCC_OFFSET)
#define AHB1EN_R_OFFSET (0x30UL)
#define RCC_AHB1EN_R (*(volatile unsigned int *) (RCC_BASE + AHB1EN_R_OFFSET))
#define MODE_R_OFFSET (0x00UL)
#define GPIOA_MODE_R (*(volatile unsigned int *) (GPIOA_BASE + MODE_R_OFFSET))
#define OD_R_OFFSET (0x14UL)
#define GPIOA_OD_R (*(volatile unsigned int *) (GPIOA_BASE + OD_R_OFFSET))
#define GPIOAEN (1U<<0)
#define PIN3 (1U<<3)
#define LED_PIN PIN3
int main(void)
{
// Enable clock access to GPIOA
RCC_AHB1EN_R |= GPIOAEN; //Set bit |=
GPIOA_MODE_R |= (1U << 6); // Set bit 6 to 1
GPIOA_MODE_R &= ~(1U << 7); // Set bit 7 to 0
// Blink LED
while(1) {
GPIOA_OD_R ^= LED_PIN;
for (int i=0; i<1000000; i++){}
}
}
I’ve only altered lines 15, 21, and 22 from the given example in the book (which works perfectly).
the original lines are
#define PIN5 (1U<<5)
and
GPIOA_MODE_R |= (1U << 10); // Set bit 10 to 1
GPIOA_MODE_R &= ~(1U << 11); // Set bit 11 to 0I've been searching through the documentation but nothing has stood out to me. I figure that I've made some silly little beginners mistake and someone here would be able to catch it. Does anyone know what I've done wrong?
