20170801——學習總結

1. 調試串口程序時,用的串口調試軟件,在串口調試軟件的下面有個s和r,注意:這裏的s和r。因爲串口程序就是STM32通過串口和電腦進行通信,STM32通過串口給電腦發送數據時,電腦收到數據後,通過串口原原本本的將數據發送給STM32,所以串口軟件上的s表示的是STM32給電腦發送數據,r表示電腦給STM32發送數據,也就是STM32接收數據,這點不要弄混。

這裏寫圖片描述

2. 有時間查一下STM32命名規則,然後每個不同名字都對應不同容量的Flash,分爲大、中、小容量的Flash;

3.串口程序部分講解:

串口初始化程序:

void uart_init(u32 bound)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 UART_InitTypeDef UART_InitStructure;
 NVIC_InitTypeDef NVIC_InitStructure;

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_UART1|RCC_APB2Pe  riph_GPIOA,ENABLE);
 UART_DeInit(UART1);

 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
 GPIO_InitStruCture.GPIO_Speed=GPIO_Speed_50Mhz;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
 GPIO_Init(&GPIOA,GPIO_InitStructure);

 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
 GPIO_Init(&GPIOA,GPIO_InitStructure);

 NVIC_InitStructure.NVIC_IRQChannel=UART1_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
 NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
 NVIV_Init(&NVIC_InitStructure);

 UART_InitSrtucture.UART_BoundRate=bound;
 UART_InitStructure.UART_WordLength=UART_WordLength_8b;
 UART_InitStructure.UART_StopBits=UART_StopBits_1;
 UART_InitStructure.UART_Parity=UART_Parity_No;
 UART_InitStructure.UART_HardwareFlowConrtol=UART_HardwareFlowConrtol_None;
 UART_InitStructure.UART_Mode=UART_Mode_Rx|UART_Mode_Tx;

 UART_Init(UART1,&UART_InitStructure);
 UART_ITConfig(UART1,UART_IT_RXNE,ENABLE);
 UART_Cmd(UART1,ENABLE);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章