国产毛片a精品毛-国产毛片黄片-国产毛片久久国产-国产毛片久久精品-青娱乐极品在线-青娱乐精品
電子工程網
標題:
STM32 4個串口同時使用,中斷接收,支持連續接收數據
[打印本頁]
作者:
gdwhwp
時間:
2013-1-8 18:55
標題:
STM32 4個串口同時使用,中斷接收,支持連續接收數據
STM32 4個串口同時使用,中斷接收,支持連續接收數據,很好用.
主程序
int main(void)
{
u16 aaa=1;
ChipHalInit(); //片內硬件初始化
ChipOutHalInit(); //片外硬件初始化
GPIO_SetBits(GPIOD,GPIO_Pin_8);
USART1_Puts("USART1 TEST 57600\r\n");
delay(100);
USART2_Puts("USART2 TEST 57600\r\n");
delay(100);
USART3_Puts("USART3 TEST 57600\r\n");
delay(100);
USART4_Puts("UART4 TEST 57600\r\n");
delay(100);
GPIO_ResetBits(GPIOD,GPIO_Pin_8);
delay(50000);
GPIO_Write(GPIOD,0XFFFF);
GPIO_ResetBits(GPIOD,GPIO_Pin_8);
#if 1
while(1)
{
delay(5000);
GPIO_Write(GPIOD,aaa);
if(aaa>=0x8000)
{
aaa = 1;
}
else
aaa = aaa<<1;
}
#endif
}
串口配置程序
void USART_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
//使能串口1,PA,AFIO總線
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_AFIO |
RCC_APB2Periph_USART1 ,
ENABLE);
/* A9 USART1_Tx */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //推挽輸出-TX
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* A10 USART1_Rx */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空輸入-RX
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = Uart1_Band_Rate_Set;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART1, &USART_ClockInitStructure);
USART_Init(USART1, &USART_InitStructure);
/* Enable the USARTx */
USART_Cmd(USART1, ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//使能串口2時鐘
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
// A2 做T2X
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// A3 做R2X
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = Uart2_Band_Rate_Set;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART2, &USART_ClockInitStructure);
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2, ENABLE);
//串口2使用接收中斷
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
// PB10 做T3X
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// PB11 做R3X
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = Uart3_Band_Rate_Set;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(USART3, &USART_ClockInitStructure);
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
// PB10 做T4X
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// PB11 做R4X
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = Uart4_Band_Rate_Set;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInit(UART4, &USART_ClockInitStructure);
USART_Init(UART4, &USART_InitStructure);
USART_Cmd(UART4, ENABLE);
USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);
}
接收中斷程序
void USART1_IRQHandler(void)
{
//接收中斷
#if 0
if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
Uart1_Get_Data=USART_ReceiveData(USART1);
Uart1_Get_Flag=1;
USART1_Putc(Uart1_Get_Data);
}
#endif
if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET)
{
TIM_Cmd(TIM3, DISABLE);
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
UART1_Data_Buff[UART1_Data_Buff_Count++] = USART_ReceiveData(USART1);
if(UART1_Data_Buff[UART1_Data_Buff_Count-1] == 0x0a)
{
if(UART1_Data_Buff[UART1_Data_Buff_Count-2] == 0x0d)
{
UART1_CMD_Process_ALL_Pointer++;
for(UART1_CMD_Process_ALL_Count__ = 0;UART1_CMD_Process_ALL_Count__
{
UART1_CMD_Process_ALL[UART1_CMD_Process_ALL_Pointer][UART1_CMD_Process_ALL_Count__] = UART1_Data_Buff[UART1_CMD_Process_ALL_Count__];
}
UART1_Data_Buff_Count = 0;
UART1_Data_Flag = 1;
}
}
}
//溢出-如果發生溢出需要先讀SR,再讀DR寄存器 則可清除不斷入中斷的問題
if(USART_GetFlagStatus(USART1,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(USART1,USART_FLAG_ORE); //讀SR
USART_ReceiveData(USART1); //讀DR
}
}
轉
http://worldcreativedesign.com/read.php?tid=7
歡迎光臨 電子工程網 (http://m.qingdxww.cn/)
Powered by Discuz! X3.4
主站蜘蛛池模板:
日韩亚洲欧美综合
|
四虎影视在线观看
|
伊人精品视频一区二区三区
|
国产亚洲国际精品福利
|
亚洲精品自在在线观看
|
青草精品视频
|
亚洲视频欧洲视频
|
中国女人18xnxx
|
自由岛三年沉淀只做精品
|
乱h好大噗嗤噗嗤烂了
|
一级黄色免费观看
|
日韩国产欧美视频
|
婷婷日日夜夜
|
国产精品AV色欲蜜臀在线
|
亚洲国语在线视频手机在线
|
亚洲啪啪网站
|
天天操天天摸天天碰
|
亚洲精选在线观看
|
国外色幼网
|
日韩国产一区二区
|
日本www在线观看
|
天天舔日日干
|
国产成人在线视频
|
一个人在线观看的视频
|
青春草在线视频免费
|
特级www
|
成人片在线播放
|
亚洲乱码中文字幕久久
|
四虎影视久久久
|
色图大全
|
啊灬啊灬啊灬快灬深高潮啦
|
欧美在线视频一区
|
亚洲欧美综合一区二区三区四区
|
天天做天天爱天天爽综合区
|
亚洲综合精品香蕉久久网97
|
久青草国产在线视频
|
有人有片的观看免费视频
|
欧洲性开放大片免费观看视频
|
色综合久久六月婷婷中文字幕
|
欧美黑人猛xxxxbbbb
|
亚洲欧美精品一区二区
|