|
串口初始化見:
STM32F407初學(xué)之串口:查詢方式收發(fā)字符串教程與源碼
http://www.zg4o1577.cn/bbs/dpj-135607-1.html
(出處: 單片機(jī)論壇)
串口中斷步驟
1.串口初始化(略)
2.配置NVIC(設(shè)置優(yōu)先級(jí)別,讓NVIC相應(yīng)該中斷)
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority((7-3),2,2));//core_cmd.h->1629
NVIC_EnableIRQ(USART1_IRQn); //core_cmd.h->1547
3.模塊級(jí)中斷使能(使能串口中斷)
USART1->CR1 |=0x01<<5;
4.編寫中斷服務(wù)函數(shù)。//函數(shù)名在啟動(dòng)文件.S100行附近
- #include "includes.h"
- int main(void)
- {
- u8 data=10;
-
- //NVIC優(yōu)先級(jí)分組
- NVIC_SetPriorityGrouping(7-2) ;
- LED_Init( );//LED初始化
- Key_Init( );
- Uart1_Init(84,115200);
-
-
- while(1)
- {
- if(revice_ok)
- {
- revice_ok=0;//清除標(biāo)志
- printf("%s\r\n",rev_buf);//回發(fā)數(shù)據(jù)給PC端
- if( strcmp((const char *)rev_buf,(const char *)"OPEN") ==0)
- {
- LED1(0);//LED2(0);LED3(0);LED4(0);
- }
- if( strcmp((const char *)rev_buf,(const char *)"CLOSE")==0 )
- {
- LED1(1);//LED2(1);LED3(1);LED4(1);
- }
- }
-
-
- }
-
- }
復(fù)制代碼
全部資料51hei下載地址:
串口中斷接收字符串-添加特殊字符作結(jié)尾.rar
(1.22 MB, 下載次數(shù): 63)
2018-9-22 21:58 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|