Question
stm32f4discovery problem with hc-05 bluetooth module
Posted on March 17, 2014 at 16:56
I'm having a problem with my usart communication between stm32f4 and hc-05 bluetooth module. I'm trying to configure the AT command of HC-05 using the stm32 board and i'm checking the response using the USB serial module and serial monitor. But i'm not getting any response. I'm using USART3. Can you please tell me if you find any problem in my pin configuration or my code. thanks
This is my pin configuration: stm32 3v pin ---------> hc-05 vcc and key pin stm32 tx --------------> hc-05 rx pin hc-05 tx ---------------> USB serial rx pin (to check the response on serial monitor) this is the code that i'm using: #include ''stm32f4xx.h'' #include ''stm32f4xx_gpio.h'' #include ''stm32f4xx_rcc.h'' #include ''stm32f4xx_usart.h'' #include <string.h> #include <stdio.h> GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; void USART_put(USART_TypeDef* USARTx, volatile char *s){ while(*s){ // wait until data register is empty while( !(USARTx->SR & 0x00000040) ); USART_SendData(USARTx, *s); while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { } *s++; } void GPIO_USART_Configuration(void){ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3); } void USART3_Configuration(void) { USART_InitStructure.USART_BaudRate = 38400; 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_Init(USART3, &USART_InitStructure); USART_Cmd(USART3, ENABLE); // enable USART2 } void usart_inisialisasi() { GPIO_USART_Configuration(); USART3_Configuration(); } int main(void) { usart_inisialisasi(); while(1) { USART_put(USART3, ''AT\r\n''); delay(2000); } }