AnsweredAssumed Answered

SMS using STM32f030C8T6 and QUECTEL M35

Question asked by c.rajeshkumar on Oct 17, 2016
Latest reply on Nov 10, 2016 by c.rajeshkumar
Hai,
      I am using Stm32f030c8t6 and Quectel M35 modem moreover i am beginner in this one, I want to send text SMS to my number. I use Coocox Co Ide for code developing and here is my code,

#include <stdint.h>
#include <stdio.h>
#include <stm32f0xx_gpio.h>
#include <stm32f0xx_rcc.h>
#include <stm32f0xx_usart.h>
#include <semihosting.h>
#include <stm32f0xx_misc.h>
#include <string.h>
 
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount);
void UART_Send1(const unsigned char pucBuffer, unsigned long ulCount);
 
int main (void)
{
    const unsigned char init[]="AT\r";
    const unsigned char init5[]="AT+CMGF=1\r";
    const unsigned char init6[]="AT+QSMSCODE=0\r";
    const unsigned char init2[]="AT+CMGS=\"89xxxxxxxx\"\n";
    const unsigned char init3[]="hai\r";
    const unsigned char init4=0x1A;
    //const unsigned char init[]="AT\r";
  int64_t i=0;
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_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;
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
 
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
 
 
 
  //Configure USART2 pins:  Rx and Tx ----------------------------
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
      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);
 
      USART_Init(USART2, &USART_InitStructure);
 
        USART_Cmd(USART2,ENABLE);
 
 
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; // Green LED
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
 
   GPIO_Init(GPIOC, & GPIO_InitStructure);
 
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; // Green LED
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
 
     GPIO_Init(GPIOB, & GPIO_InitStructure);
 
     GPIO_WriteBit(GPIOB, GPIO_Pin_14,Bit_SET);
     for (i=0; i<2500000;i++);
     GPIO_WriteBit(GPIOB, GPIO_Pin_14, Bit_RESET);
 
 
 
 
     for (i=0; i<4000000;i++);
     UARTSend(init,sizeof(init));    //sending AT
     for (i=0; i<2000000;i++);
        UARTSend(init5,sizeof(init5));   //sending AT+CMGF=1
        for (i=0; i<1000000;i++);
        UARTSend(init6,sizeof(init6));  // sending AT+QSMSCODE
     for (i=0; i<1000000;i++);
     UARTSend(init2,sizeof(init2));   // sending AT+CMGS
 
     for (i=0; i<1000000;i++);
     while (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // waiting for '>'
        UARTSend(init3,sizeof(init3));   // sending message
   for (i=0; i<1000000;i++);
     UART_Send1(init4,sizeof(init4));   // sending CTRL+Z
 
 
  //Configure USART2 setting:         ----------------------------
 
 
  while(1)
  {
 
 
  }
 
  return 0;
}
 
 
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
 
 
    while(ulCount--)
    {
        USART_SendData(USART2,(uint16_t) *pucBuffer++);// Last Version USART_SendData(USART1,(uint16_t) *pucBuffer++);
        /* Loop until the end of transmission */
        while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
        {
        }
    }
 
}
 
 
 
void UART_Send1(const unsigned char pucBuffer, unsigned long ulCount)
{
 
    while(ulCount--)
    {
        USART_SendData(USART2,(uint16_t) pucBuffer);// Last Version USART_SendData(USART1,(uint16_t) *pucBuffer++);
        /* Loop until the end of transmission */
        while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
        {
        }
    }
}

when i execute above code what i get was empty message, But when i connect the modem to Serial terminal and give the above AT commands as same as i used in the code, it works fine.  I don't know where the things got wrong. 

Outcomes