STM32F4 Apollo Register Lights LED Lamp

Posted on
  • Learning steps:

 

Using registers to light up LED lights requires the following steps.LEDThe lamp belongs to the peripheral part. First it needs to turn on the clock power of the peripheral, and then it needs to turn on the clock power of the peripheral.LEDThe lamp isPB1Mouth, (the chip is Apollo of positive point atom), then defineGPIOBThe output mode of the port is pull-up, push-pull and push-pull.100MThe final definitionBOral1The pin can be lighted at a low level.

 

This part of the content is a bit time-consuming, and finally found that the key reason is that the reset key was not pressed during debugging. This is why I am very silent. No wonder I downloaded the program before. When I went to turn on the power the next morning, a light came on. The original program was written correctly.~~~

 

  • Errors and summaries:

Error is the key problem. After downloading the program, I saw that the light was not on, so I continued to modify the program, modifying several versions. Maybe it was right before. In addition, the process also made a lot of changes and checks on the code, because the address of the register needs to be searched by itself, all sometimes miswritten, but I should have read it many times, now I am very impressed. First of all, ensure that the clock can turn on AHB1, then define the GPIOB port, the initial address and offset address must be added to the right.

There are many bitwise operations of C language code in the middle. Now let’s add that:

Position |= Clear up=&=~

A > b means that the number a moves to the right B bit a<

It is necessary to modify the mini plate of target for 8 and Apollo for 12 in the magic wand.

  • Code:

#include "stm32f429xx.h"

int main(void)
{
// Enabling Clock AHB1
    *(unsigned int *)0x40023830 |= (1<<1);
// control IO port output
    *(unsigned int *)0x40020400 &= 0x00000000;
    *(unsigned int *)0x40020400 |= (1<<2);
    
    *(unsigned int *)0x40020404 &= 0x00000000;
    
    *(unsigned int *)0x40020408 &= 0x00000000;
    *(unsigned int *)0x40020408 |= (1<<3);
    
    *(unsigned int *)0x4002040C &= 0x00000000;
    *(unsigned int *)0x4002040C |= (1<<2);


//ODR register
    *(unsigned int *)0x40020414 &=~(1<<1);
    
}


Void system minit (void) // Deceptive compiler will not report errors
{


}

 

Leave a Reply

Your email address will not be published.