/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / stm32 and gsm module communication(AT command) via usart

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 Family
  •  » stm32 and gsm module communication(AT command) via usart

# 1   2012-09-23 10:37:03 stm32 and gsm module communication(AT command) via usart

nazuhin
New member
Registered: 2012-09-23
Posts: 1

stm32 and gsm module communication(AT command) via usart

hi all,i am recently working on a project that sending AT command to gsm module from stm32vl discovery via usart and receiving response with interrupt but i am very confused about usart interfaces.i cant receive response from gsm module.i am using stm32vl discovery and ublox leon g100 gsm module usart1 and usart3 and terminal.here is my code :

#include "stm32f10x.h"
#include "stdio.h"



/*###################################################################################*/
/*###################################################################################*/

void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void USART_Configuration(void);
void USART1_IRQHandler(void);
void USART3_IRQHandler(void);




/*###################################################################################*/
/*###################################################################################*/

void RCC_Configuration(void)
{
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
}


/*###################################################################################*/
/*###################################################################################*/

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
 
  /* Configuring USART1_Tx as 'alternate function push-pull' */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
  /* Configuring USART1_Rx as 'input floating' */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
     /* Configuring USART3_Tx as 'alternate function push-pull' */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
  /* Configuring USART3_Rx as 'input floating' */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);



/*###################################################################################*/
/*###################################################################################*/

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
 
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
   
    NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}


/*###################################################################################*/
/*###################################################################################*/

void USART_Configuration(void){
       
            USART_InitTypeDef USART_InitStructure;
           
            USART_InitStructure.USART_BaudRate = 9600;
            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_Init(USART3, &USART_InitStructure);
            USART_Cmd(USART3, ENABLE);
           
            USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
            USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
           
}


/*###################################################################################*/
/*###################################################################################*/
u8 command;
u8 response;
int main(void)
{
 
  RCC_Configuration();
  GPIO_Configuration();
    USART_Configuration();
  NVIC_Configuration();
 
    while (1);
   
}
     

/*###################################################################################*/
/*###################################################################################*/

int fputc(int ch, FILE * f) //retargetting printf
{
 
  USART_SendData(USART1, (u8) ch);
  while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
  return ch;



/*###################################################################################*/
/*###################################################################################*/

void USART1_IRQHandler(void)
{
 
    command=USART_ReceiveData(USART1);
    printf("%c",command);
   
    USART_SendData(USART3, (u8) command);
   
   


/*###################################################################################*/
/*###################################################################################*/

void USART3_IRQHandler(void){

    response=USART_ReceiveData(USART3);
   
    printf("%c",response);
   
   
}


module is using usart3 and i am using usart1 in order to watch command&response on terminal.can anyone help me where am i wrong?

Offline

 

  • Index
  •  » STM32 Family
  •  » stm32 and gsm module communication(AT command) via usart

Board footer