int main(void)
{
uint8_t i;
uint8_t buzzer[20]={0xAA,0xA0,0xFF,0xF8,0x8F,0x88,0xFF};
Sys
tick_Config(SystemCoreClock/1000);
USART_Config();
while(1){
if(RXOVER == 1){
USART_SendString3(buzzer);
USART_SendString1(USART_RXBUF);
for(i=0;i<8;i++){
USART_RXBUF
= 0; //清空接收区
}
RXOVER = 0;
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
}
}
}
void USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
NVIC_Configuration();
//配置USART2 TX引脚工作模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//配置USART2 RX引脚工作模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//串口2工作模式配置
USART_InitStructure.USART_BaudRate = 19200;
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_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
USART_Cmd(USART2, ENABLE);
}
/**
* @说明 配置中断向量控制器
* @参数 None
* @返回值 None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the RTC Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/******************************************************************************/
/**
* @brief This function handles PPP interrupt request.
* @param None
* @retval None
*/
void USART2_IRQHandler(void)
{
uint8_t temp;
if(USART_GetITStatus(USART2,USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
temp = USART_ReceiveData(USART2);
if(RXCUNT==8)
{
RXCUNT = 0;
RXOVER = 1;
USART_ITConfig(USART2,USART_IT_RXNE,DISABLE);
}
else
{
USART_RXBUF[RXCUNT] = temp;
++RXCUNT;
}
}
}
请大神分析一下为什么用串口调试会显示这样的结果呢?为什么后面会多出3个00.
-
for(i=0;i<8;i++){
USART_RXBUF = 0; //清空接收区
}
这里应该是USART_RXBUF [i]= 0吧
一周热门 更多>