AnsweredAssumed Answered

send sms with sim900 on stm32f107

Question asked by lepore.mario on Dec 16, 2013
Latest reply on Dec 18, 2013 by sung.chen_chung
I have to send a sms with sim900 form my stm32f107 board. I wrote this code, but it does not work. I can't understand why.

/* Includes */


#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "misc.h"
#define CR 13
#define LF 10


void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void sendMessage(char header[23], char message[150]);
void Delay(__IO uint32_t nCount);




int main(void){
     char SendMessageTO[23] = "AT+CMGS=”+3473802890”";
     char SendMessageMESSAGE[150] = " THIS IS A SAMPLE MESSAGE            ";
     USART_InitTypeDef USART_InitStructure;


     /* System Clocks Configuration */
     RCC_Configuration();


     /* NVIC configuration */
     //NVIC_Configuration();


     /* Configure the GPIO ports */
     GPIO_Configuration();


     /* USARTx configuration ------------------------------------------------------*/
     /* USARTx configured as follow:
        - BaudRate = 9600 baud
        - Word Length = 8 Bits
        - Two Stop Bit
        - Odd parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
      */
     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);


     sendMessage(SendMessageTO, SendMessageMESSAGE);


     while(1)
     {
     }
}




void RCC_Configuration(void)
{
     /* Enable GPIO clock */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
     /* Enable USART2 Clock */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
}






void GPIO_Configuration(void)
{
     GPIO_InitTypeDef GPIO_InitStructure;




     /* Configure USART1 Rx as input floating */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
     GPIO_Init(GPIOA,&GPIO_InitStructure);


     /* Configure 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);
}




void sendMessage(char header[23], char message[150])
{
     int ctr;
     for (ctr=0;ctr<23;ctr++)
     {
          USART_SendData(USART1,(int)header[ctr] );
          Delay(10);
     }
     USART_SendData(USART1,CR);
     Delay(10);
     USART_SendData(USART1,LF);
     Delay(10);


     Delay(1000);


     for (ctr=0;ctr<150;ctr++)
     {
          USART_SendData(USART1,(int) message[ctr] );
     }
     USART_SendData(USART1,CR);
     USART_SendData(USART1,LF);


}


void Delay(__IO uint32_t nCount) //in millisecond
{
     nCount = nCount * 5940 *2;//381;
     while(nCount--)
     {
     }
}


void NVIC_Configuration(void)
{
     NVIC_InitTypeDef NVIC_InitStructure;


#ifdef  VECT_TAB_RAM
     /* Set the Vector Table base location at 0x20000000 */
     NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
     /* Set the Vector Table base location at 0x08000000 */
     NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif


     /* Enable the TIM2 global Interrupt */
     //NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);
}


Outcomes