新手上路
- 积分
- 32
- 金钱
- 32
- 注册时间
- 2017-10-27
- 在线时间
- 6 小时
|
1金钱
本人新手,想做一个串口接收数组的程序,现在串口接收数组的函数写出来之后,数组里面却没有我想要的数据,这种情况应该怎么办?附上我的程序,麻烦各位大神帮忙解答,谢谢!这是串口配置
void USART1_Init(){
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
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_Tx | USART_Mode_Rx;
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //
USART_Cmd(USART1, ENABLE);//
}
下面是中断服务函数
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ReData[nCount ] = USART_ReceiveData(USART1);
nCount++;
}
USART_ClearITPendingBit(USART1, USART_IT_RXNE);//Çå3yÖD¶Ï±ê־λ
}
|
最佳答案
查看完整内容[请看2#楼]
你赋值的结构体就没调用 USART_Init(USART1, &USART_InitStructure);
|