学前班
最后登录1970-1-1
在线时间 小时
注册时间2017-8-5
|
各位大神,才开始学STM32,最近想实现指南者与蓝牙HC-06通信,在给HC-06发送 “AT” 指令时,按理会收到 “OK” 应答,但是没有。查了老半天程序,没有发现错误,帮忙看看。
bsp_usart_blt.h
- #define BLT_USART_BAUD_RATE 115200
- #define BLT_USARTx USART2
- #define BLT_USART_APBxClock_FUN RCC_APB1PeriphClockCmd
- #define BLT_USART_CLK RCC_APB1Periph_USART2
- #define BLT_USART_GPIO_APBxClock_FUN RCC_APB2PeriphClockCmd
- #define BLT_USART_GPIO_CLK RCC_APB2Periph_GPIOA
- #define BLT_USART_TX_PORT GPIOA
- #define BLT_USART_TX_PIN GPIO_Pin_2
- #define BLT_USART_RX_PORT GPIOA
- #define BLT_USART_RX_PIN GPIO_Pin_3
- #define BLT_USART_IRQ USART2_IRQn
- #define BLT_USART_IRQHandler USART2_IRQHandler
- void BLT_USART_Config(void); // 配置蓝牙串口
- void Usart_SendStr_length( USART_TypeDef * pUSARTx, uint8_t *str,uint32_t strlen );
- void Usart_SendString( USART_TypeDef * pUSARTx, uint8_t *str);
- void bsp_USART_Process(void); // 中断服务程序调用的函数,主要是读取接收到的数据
- char *get_rebuff(uint16_t *len);
- void clean_rebuff(void);
复制代码 bsp_usart_blt.c
- /// 串口2接收中断
- static void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Configure the NVIC Preemption Priority Bits */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- /* Enable the USARTy Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = BLT_USART_IRQ;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- //外部调用配置函数
- void BLT_USART_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- /* config USART2 clock */
- BLT_USART_APBxClock_FUN(BLT_USART_CLK, ENABLE);
- BLT_USART_GPIO_APBxClock_FUN(BLT_USART_GPIO_CLK, ENABLE);
- /* USART2 GPIO config */
- /* Configure USART2 Tx (PA.02) as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = BLT_USART_TX_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(BLT_USART_TX_PORT, &GPIO_InitStructure);
-
- /* Configure USART2 Rx (PA.03) as input floating */
- GPIO_InitStructure.GPIO_Pin = BLT_USART_RX_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(BLT_USART_RX_PORT, &GPIO_InitStructure);
-
- /* USART2 mode config */
- USART_InitStructure.USART_BaudRate = BLT_USART_BAUD_RATE;
- 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(BLT_USARTx, &USART_InitStructure);
-
- /* 中断 */
- NVIC_Configuration();
- /* 使能接收中断 */
- USART_ITConfig(BLT_USARTx, USART_IT_RXNE, ENABLE);
- USART_Cmd(BLT_USARTx, ENABLE);
- USART_ClearFlag(BLT_USARTx, USART_FLAG_TC);
- }
复制代码 然后中断服务入口程序是写在 stm32f10x_it.c 中的。。。问题是发送AT后读不到数据。。。
|
|