当前位置:网站首页>Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method

Blue Bridge Cup embedded (F103) -1 STM32 clock operation and led operation method

2022-07-08 01:18:00 Youyu hesitant squid

Blue Bridge Cup (F103)-1.STM32 Clock operation and LED Operation method

One 、STM32 Clock introduction

1. file location :
Open the resource packet → open 5- Competition board chip information → open STM32_CN.pdf
2. Introduction of clock tree (P56 Clock block diagram )
HSE OSC High speed external clock signal , In the Blue Bridge Cup F103rbt6 Develop on-board external crystal oscillator HSE=8MHz, Then a selector can choose 8MHz Or frequency division /2 by 4MHz, We choose 8MHz, Through the frequency multiplier , Frequency multiplier selection ×9 Make it work at the maximum output frequency 72MHz. Last pass AHB Prescaler output to peripheral .APB1 The maximum is 36MHz,APB2 The maximum is 72MHz.
3. Introduction of system structure (P25 System structure )
Mainly understand reset and clock control (RCC) Connect AHB The system bus , The bridge 1 by APB2, From the above ,APB2 For high frequency , The maximum clock frequency is 72MHz. The bridge 2 by APB1, For low frequency , The maximum clock frequency is 36Hz.
Mainly understand APB1( low speed ) and APB2( High speed ) Attached to APB equipment , Common peripherals are as follows :
APB1:I2C1,I2C2,UART4,UART5,SPI2,SPI3,RTC,TIM2~TIM7
APB2;ADC 1~3,USART1,SPI1,TIM1,TIM8,GPIO A ~ G,EXT1,AFIO
4. Turn on the peripheral clock with the library function

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);// Turn on GPIOC Peripheral clock 

Two 、LED Operation method

1.LED initialization
Procedure steps
LED initialization : Turn on the peripheral clock → Structure initialization → initialization GPIO
The code is as follows :

void LED_Init(void)
{
    
	GPIO_InitTypeDef GPIO_structure;// Declared structure 
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);/ Turn on the peripheral clock 
	GPIO_structure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|
	GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;// Initialization pin 
	GPIO_structure.GPIO_Speed = GPIO_Speed_50MHz;// Initialize settings GPIO output frequency 
	GPIO_structure.GPIO_Mode = GPIO_Mode_Out_PP;// Initialize settings GPIO Pattern 
	GPIO_Init(GPIOC,&GPIO_structure);//GPIO initialization 
}

2. Schematic diagram interpretation
(1)LED The circuit principle diagram
LED The circuit principle diagram
explain :LED Adopt common anode connection , Output low level is on LED.
Latch M74HC573:
 Insert picture description here
Function explanation
According to the function description in the data book ,OE(Output Enable) Low power level , Output enable , In the circuit schematic diagram OE The terminal is directly grounded ,74HC573 Always in the enabled state .LE(Latch Enable) For high voltage ,D And Q Also for H or L.
 Insert picture description here
 Insert picture description here
Be careful :
The left and right sides are connected through jumper caps , And STM32 Pin to pin

3. Realize the running water lamp
Procedure steps
Running water lamp : Lighten up 1 individual LED→ Define an array → Use circulation to make LED Turn on .
The code is as follows :

void LED_contorl(void)
{
    
	u16 LED_ctrl;
	u8 LED_locate;
	u16 LED_code[8]={
    0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
	for(LED_locate=0;LED_locate<8;LED_locate++)
	{
    
		LED_ctrl=LED_code[LED_locate];
		GPIO_ResetBits(GPIOC,LED_ctrl<<8);
		Delay_Ms(500);
		GPIO_SetBits(GPIOC,LED_ctrl<<8);	
	}
}

原网站

版权声明
本文为[Youyu hesitant squid]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130545293779.html