本帖最后由 宋一喵 于 2014-9-15 19:02 编辑
我对照固件库的例子修改而来,使用USART3进行查询接收,但是没能接收到数据,手上没JLINK,甚是郁闷,请大虾们帮我看看程序是否有问题。
下面是配置:
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure; //定义串口初始化结构体
/* config USART3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3 | RCC_APB2Periph_GPIOB, ENABLE);
/* USART3 GPIO config */
/* Configure USART3 Tx (PB.10) as alternate function push-pull 推拉输出模式*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART3 Rx (PB.11) as input floating 浮点输入模式*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USART3 mode config */
USART_InitStructure.USART_BaudRate = 9600;//波特率9600
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;//禁用RTSCTS硬件流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //使能发送接收
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
然后再主函数里循环查询:
void main()
{
u8 ucBluetoothValue;
USART3_Config();
while (1)
{
/* Wait until a byte is received */
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET)
{
}
ucBluetoothValue = (u8)USART_ReceiveData(USART3);
//USART_ClearFlag(USART3,USART_FLAG_RXNE);
LED1( OFF );
}
}
也试过改成这样:
void main()
{
u8 ucBluetoothValue;
USART3_Config();
while (1)
{
if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)
{
uart1_get_data = USART_ReceiveData(USART1);
LED1( OFF );
}
}
}
还是不行。
求指点。 |