和电脑通讯,电脑用的是secureCRT。电脑上能接受到 板子发送的字符,但电脑发的,板子却接受不到。
大神帮忙看看出什么问题了
初始化:
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* ʹÄÜ USART1 ʱÖÓ*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* USART1 ʹÓÃIO¶Ë¿ÚÅäÖà */
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_FLOA
tiNG; //¸¡¿ÕÊäÈë
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯GPIOA
/* USART1 ¹¤×÷ģʽÅäÖà */
USART_InitStructure.USART_BaudRate = 115200; //²¨ÌØÂÊÉèÖãº115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //Êý¾ÝλÊýÉèÖãº8λ
USART_InitStructure.USART_StopBits = USART_StopBits_1; //ֹͣλÉèÖãº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_ITConfig(USART1, USART_IT_TXE, DISABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ClearFlag(USART1, USART_IT_RXNE);
USART_ClearFlag(USART1, USART_FLAG_TC);
USART_ClearFlag(USART1, USART_FLAG_RXNE);
USART_Cmd(USART1, ENABLE);
}
读写方法:
void UART1SendByte(unsigned char SendData)
{
USART_SendData(USART1,SendData);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
}
unsigned char UART1GetByte(unsigned char* GetData)
{
if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
{ return 0;//ûÓÐÊÕµ½Êý¾Ý
}
*GetData = USART_ReceiveData(USART1);
return 1;//ÊÕµ½Êý¾Ý
}
用户任务:
void Task_232(void *p_arg)
{
unsigned char *GetData;
while (1)
{
while(UART1GetByte(GetData))
{
UART1SendByte('9');
}
OSTimeDlyHMSM(0, 0,0,1);
}
}
一周热门 更多>