各位大神,小弟编写了一个STM8L152C6单片机USART一收一发程序,出现一个问题,在发送然后再返回数据时会丢失数据,而且是每隔11个丢一个,比如发1 2 3 4 5 6 7 8 9 10 11 12 13 14 15.。。。就会丢失12 23 34,
主函数部分:
/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
#include "stm8l15x.h"
#include "stm8l15x_conf.h"
void delayms(unsigned int x)
{
unsigned int j=0,i=0;
for(;i<x;i++)
for(;j<65535;j++);
}
main()
{
GPIO_TypeDef GPIO_Struct;
GPIO_DeInit(&GPIO_Struct);
GPIO_Init(GPIOB,(GPIO_Pin_4|GPIO_Pin_5),GPIO_Mode_Out_PP_Low_Fast);
GPIO_Write(GPIOB,0x10);
GPIO_Init(GPIOC,GPIO_Pin_2,GPIO_Mode_In_PU_No_IT);
GPIO_Init(GPIOC,GPIO_Pin_3,GPIO_Mode_Out_PP_Low_Fast);
GPIO_Init(GPIOE,GPIO_Pin_0,GPIO_Mode_Out_PP_Low_Fast);
CLK_PeripheralClockConfig(CLK_Peripheral_USART1,ENABLE);
USART_DeInit(USART1);
USART_Init(USART1,9600,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,( USART_Mode_TypeDef)(USART_Mode_Rx|USART_Mode_Tx));
USART_ClockInit(USART1,USART_Clock_Disable,USART_CPOL_Low,USART_CPHA_2Edge,USART_LastBit_Disable);
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_Cmd(USART1,ENABLE);
enableInterrupts();
GPIO_SetBits (GPIOE,GPIO_Pin_0);
while (1)
{
}
}
中断函数
@far @interrupt void USART_RX_IRQHandler (void) //28
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
Buf=USART_ReceiveData8(USART1);
// while((USART1->SR&0x80)==0x00);
USART_SendData8(USART1,Buf);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
}
谢谢各位大神了 |