#include "LIB_Config.h"
void MY_NVIC_Configura
tion(void)//配置中断优先级
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void MY_USART2_Init()
{
USART_InitTypeDef tUSART;
//NVIC_InitTypeDef NVIC_InitStructure;
/* config USART2 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* USART2 mode config */
tUSART.USART_BaudRate = 250000;
tUSART.USART_WordLength = USART_WordLength_9b;
tUSART.USART_StopBits = USART_StopBits_1;
tUSART.USART_Parity = USART_Parity_No;
tUSART.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
tUSART.USART_Mode = USART_Mode_Rx;
USART_Init(USART2, &tUSART);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
MY_NVIC_Configuration();
USART_Cmd(USART2, ENABLE);
}
uint16_t DmxData[20] = {0};
uint16_t DmxHeadFlag = 0;
uint16_t UDR = 0;
uint8_t OpenRecFlag = 0;
void USART2_IRQHandler(void)
{
static uint8_t dmxaddress = 0;
if(USART2->SR&(1<<5))//接收到数据
{
UDR = USART2->DR;
DmxHeadFlag = UDR&0x100;
if(DmxHeadFlag == 0)
{
dmxaddress = 0;
OpenRecFlag = 1;
}
else
{
if(OpenRecFlag)
{
DmxData[dmxaddress++] = UDR&0xff;
}
if(dmxaddress > 10)
{
OpenRecFlag = 0;
}
}
USART2->SR &= ~(1<<5);
}
}
-
- tUSART.USART_BaudRate = 250000;
- tUSART.USART_WordLength = USART_WordLength_9b;
复制代码250kbps , 9 WordLength ???
一周热门 更多>