cancel
Showing results for 
Search instead for 
Did you mean: 

message transmission using GSM and stm32f303

2013ee139
Associate II
Posted on September 02, 2016 at 09:10

Hello,

I am using gsm module to transmit a message using USART of stm32f303. I have used following commands for gsm

AT+CMGF=1

AT+CMGS=''+923046761738''

at the end it requires CTRL+Z to send the message 

but usart is not sending the ctrl+z i am attacting my code please help me

''char configuration[150];

char configuration[]=''AT+CMGF=1\r\n\0'';

char message[150];

void RCC_Configuration(void)

{

  /* Enable GPIO clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

 

  /* Enable USART clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

}

 

/**************************************************************************************/

  

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

  /* Connect PA9 to USART1_Tx */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7);

 

  /* Connect PA10 to USART1_Rx */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7);

 

  /* Configure USART Tx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 

  /* Configure USART Rx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

 

/**************************************************************************************/

 

void USART1_Configuration(void)

{

  USART_InitTypeDef USART_InitStructure;

 

  /* USART resources configuration (Clock, GPIO pins and USART registers) ----*/

  /* USART configured as follow:

        - BaudRate = 9600 baud

        - Word Length = 8 Bits

        - One Stop Bit

        - No parity

        - Hardware flow control disabled (RTS and CTS signals)

        - Receive and transmit enabled

  */

  USART_InitStructure.USART_BaudRate = 115200;

  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 configuration */

  USART_Init(USART1, &USART_InitStructure);

 

  /* Enable USART */

  USART_Cmd(USART1, ENABLE);

}

void gsm_message(char *ptr)

while(*ptr)

{

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty

USART_SendData(USART1, *ptr);

ptr++;

}

}

int main(void)

{  

//

  RCC_Configuration();

  

  GPIO_Configuration();

  

  USART1_Configuration();

  

  //while(1)

  //{

gsm_message(''AT+CMGF=1\r\n'');

//Delay(1);

gsm_message(''AT+CMGS=\''+923046761738\''\r\n'');

//Delay(10);

gsm_message(''hello'');

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty

    USART_SendData(USART1,(char)0x1A);

gsm_message(''\r\n'');

//Delay(10);

  

  //}

  

  while(1); // Don't want to exit

}

#i2c #stm32f303vct6 #stm32f3
0 REPLIES 0