Send SMS using STM32 & SIM7600

In this project, we send an SMS when the STM32 powers on. This is a simple setup with few lines of codes so that anyone can get started with UART communication and AT commands. It can be used for real world application when some power switch is on we can get notified.

SIM7600 comes in different version. The one I am using is SIM7600G (Global) that can work with many bands. I checked here in Australia with two different providers (Telstra and Vodafone). Both sim cards worked fine.

The pin outs are quite simple. Connect four pins VCC,GND,UART(RX) and UART(TX), it will just work. This module includes proper power regulator, so we can connect 5V to the V pin. Also the TX/RX serial communication already includes necessary 3.3V level shifter. So we can connect to 3.3V ESP or STM microcontroller directly.

AT command manual, Schematic and Datasheet can be found in the following links. https://www.adrive.com/public/bPqyGe/BK-SIM7600E-H.zip

Items can be purchased from https://www.aliexpress.com/store/605000. I bought my items from https://www.aliexpress.com/item/4000224044192.html

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic program using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A

Wiring diagram

Diagram Image

STM32CubeIDE Settings

Enable USART1 asynchronous

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN Includes */
#include <string.h>
#include <stdio.h>
/* USER CODE END Includes */

  /* USER CODE BEGIN 2 */
  char mobileNumber[] = "+61498749497";  // Enter the Mobile Number you want to send to
  char ATcommand[80];
  uint8_t buffer[30] = {0};
  uint8_t ATisOK = 0;
  while(!ATisOK){
  		sprintf(ATcommand,"AT\r\n");
  		HAL_UART_Transmit(&huart1,(uint8_t *)ATcommand,strlen(ATcommand),1000);
  		HAL_UART_Receive (&huart1, buffer, 30, 100);
  		HAL_Delay(1000);
  		if(strstr((char *)buffer,"OK")){
  			ATisOK = 1;
  		}
  		HAL_Delay(1000);
  		memset(buffer,0,sizeof(buffer));
  }
  sprintf(ATcommand,"AT+CMGF=1\r\n");
  HAL_UART_Transmit(&huart1,(uint8_t *)ATcommand,strlen(ATcommand),1000);
  HAL_UART_Receive (&huart1, buffer, 30, 100);
  HAL_Delay(1000);
  memset(buffer,0,sizeof(buffer));
  sprintf(ATcommand,"AT+CMGS=\"%s\"\r\n",mobileNumber);
  HAL_UART_Transmit(&huart1,(uint8_t *)ATcommand,strlen(ATcommand),1000);
  HAL_Delay(100);
  sprintf(ATcommand,"Hello World, STM32 started%c",0x1a);
  HAL_UART_Transmit(&huart1,(uint8_t *)ATcommand,strlen(ATcommand),1000);
  HAL_UART_Receive (&huart1, buffer, 30, 100);
  memset(buffer,0,sizeof(buffer));
  HAL_Delay(4000);
  /* USER CODE END 2 */

Demonstration