|
1、STM32通過串口調(diào)試助手可以正常收發(fā),傳輸?shù)臄?shù)據(jù)沒有錯誤,
2、藍(lán)牙HC-08通過串口調(diào)試助手也可以正常收發(fā),傳輸?shù)臄?shù)據(jù)沒有錯誤,
3、STM32和藍(lán)牙連在一起進(jìn)行通信,波特率都是9600,不能正常收發(fā),
通過串口發(fā)送數(shù)據(jù)01,STM32能接收數(shù)據(jù)01,并將數(shù)據(jù)01返回都串口窗口顯示01,手機(jī)也能接收到數(shù)據(jù)01,指示燈LED有亮滅,但通過手機(jī)發(fā)送數(shù)據(jù)01到STM32沒有反應(yīng),手機(jī)沒有接收到返回的數(shù)據(jù),串口調(diào)試窗口也沒有接收到數(shù)據(jù),指示燈也沒有變化,證明沒有進(jìn)入串口中斷程序,不知道原因在哪?希望各位大佬能幫忙解決一下,謝謝!
4、程序如下:
void USART1_Init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//TX
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure)
USART_InitStructure.USART_BaudRate = bound;
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_Cmd(USART1, ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler(void) //串口中斷服務(wù)程序
{
led1=!led1; //進(jìn)入串口程序指示燈
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
r = USART_ReceiveData(USART1);//(USART1->DR);
USART_SendData(USART1,r);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC) != SET);
}
USART_ClearFlag(USART1,USART_FLAG_TC);
}
|
-
|