cancel
Showing results for 
Search instead for 
Did you mean: 

SMS using STM32f030C8T6 and QUECTEL M35

raj11
Associate II
Posted on October 17, 2016 at 09:15

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. #quectel-m35 #uart #stm32f030
4 REPLIES 4
Posted on October 17, 2016 at 17:04

The modem will respond with OK, ERROR, etc to the commands you send it, these responses will tell you what is happening, and if things were successful.

Spinning in a loop for some arbitrary time does NOT achieve the interaction the modem requires, and is apt to fail.

Make sure the modem is registering with the network.

You could also make an application that forwards the modem serial data to/from your terminal connection, you could use this and RealTerm, etc to walk through the AT command interaction, and confirm the modem is behaving as expected.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 17, 2016 at 17:12

Use strlen() to compute string lengths, sizeof() will include the NUL, which you don't want to send.

sizeof()-1 could be used, but would create portability or consistency issues in the future.

Also front test for TXE rather than back test for TC, the TXE indicates is the register is empty

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
raj11
Associate II
Posted on October 18, 2016 at 06:25

Hai Clive1

   thanks for your help. its the null character which is making the trouble. when i used sizeof()-1. The message sending is working properly. thanks for your help once again.

raj11
Associate II
Posted on November 10, 2016 at 12:17