我将接收到的数据存入数组中,存满了就返回数组的全部值,但是返回的值不对,比如我发送00 11 10 01 00 11 10 01这8组数,完了应该全部返回,但是返回的数据不对,
unsigned char a_RxBuf[8];
unsigned char usRxWrite=0;
unsigned char Rxcount=0;
unsigned char Rxsize=8;
void InitUart(void)
{
USART1_Config();
}
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);/* 使能接收中断 */
USART_Cmd(USART1, ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler(void)
{
/* 处理接收中断 */
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
a_RxBuf[usRxWrite++]=USART_ReceiveData(USART1);
if(usRxWrite==Rxsize)
{
for(Rxcount=0;Rxcount<Rxsize;Rxcount++)
{
USART_SendData(USART1, a_RxBuf[Rxcount]);
}
usRxWrite=0;
Rxcount=0;
}
USART_ClearFlag(USART1,USART_FLAG_TC);
}
}
这个是数据已经存入到数组里边,而且FOR函数也正确运行,也已经发送了,但是不知道数据发送到哪里去了
|