AnsweredAssumed Answered

Struggling with HC05 Module for AT Command

Question asked by ghanmy.montassar on Feb 13, 2015
Latest reply on Feb 14, 2015 by ghanmy.montassar

I'm getting some hard time trying to make my HC05 to execute an AT command from my stm32f4 , first it seemed that the problem was that the module was not in AT mode, now that i got it to enter AT mode it still is not responding , here is my code:

#include <stm32f4xx.h>
#include <stm32f4xx_usart.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_rcc.h>

void init_usart(void){

GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;

/* enable peripheral clock for USART2 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

/* GPIOA Configuration: USART2 TX on PA2 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Connect USART2 pins to AF2 */
// TX = PA2

GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

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(USART2, &USART_InitStructure);

USART_Cmd(USART2, ENABLE); // enable USART2

}

int main(void){

init_usart();

     USART_SendData(USART2, 'A'); 
     USART_SendData(USART2, 'T'); 
     USART_SendData(USART2, '+'); 
     USART_SendData(USART2, 'P');
     USART_SendData(USART2, 'I'); 
     USART_SendData(USART2, 'N'); 
     USART_SendData(USART2, '='); 
     USART_SendData(USART2, '1'); 
     USART_SendData(USART2, '7'); 
     USART_SendData(USART2, '8');
     USART_SendData(USART2, '9'); 

}

I tried with Both 9600 and 38400 for the baud rate but nothing works. Anyone can point me to the right direction?
Thank you !!! 

Outcomes