cancel
Showing results for 
Search instead for 
Did you mean: 

SIM800L doesn't respond to AT commands.

Scusi
Associate II

Hi there,

I'm using a stm32f401re with stm32cubemx and keil uVision5.

I'm trying to interface the mcu with the gsm module.

I'm sure that the module works fine. I tested it with arduino and it worked without any issues. When I try to send any AT command to the module using the HAL USART library I'm not able to receive any answer from the module. I have tried both polling mode and it mode but no success.

I attach the code.

Do you have any advice?

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "gpio.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
 
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
 
/* USER CODE BEGIN PV */
uint8_t TX[]="AT\r\n";
uint8_t RX[3];
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
  
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART6_UART_Init();
  /* USER CODE BEGIN 2 */
 
  /* USER CODE END 2 */
  
	HAL_UART_Transmit_IT(&huart6, TX, sizeof(TX));
	HAL_UART_Receive_IT(&huart6, RX, sizeof(RX));
	
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
		HAL_UART_Transmit_IT(&huart6, TX, sizeof(TX));
		HAL_Delay(3000);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
 
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 
  /** Configure the main internal regulator output voltage 
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}
 
/* USER CODE BEGIN 4 */
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	HAL_UART_Transmit_IT(&huart6, RX, sizeof(RX));
	HAL_UART_Receive_IT(&huart6, RX, sizeof(RX));
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
	
}
/* USER CODE END 4 */
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
 
  /* USER CODE END Error_Handler_Debug */
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{ 
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
  ******************************************************************************
  * File Name          : USART.c
  * Description        : This file provides code for the configuration
  *                      of the USART instances.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
 
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
 
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
UART_HandleTypeDef huart6;
 
/* USART6 init function */
 
void MX_USART6_UART_Init(void)
{
 
  huart6.Instance = USART6;
  huart6.Init.BaudRate = 9600;
  huart6.Init.WordLength = UART_WORDLENGTH_8B;
  huart6.Init.StopBits = UART_STOPBITS_1;
  huart6.Init.Parity = UART_PARITY_NONE;
  huart6.Init.Mode = UART_MODE_TX_RX;
  huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart6.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart6) != HAL_OK)
  {
    Error_Handler();
  }
 
}
 
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(uartHandle->Instance==USART6)
  {
  /* USER CODE BEGIN USART6_MspInit 0 */
 
  /* USER CODE END USART6_MspInit 0 */
    /* USART6 clock enable */
    __HAL_RCC_USART6_CLK_ENABLE();
  
    __HAL_RCC_GPIOC_CLK_ENABLE();
    /**USART6 GPIO Configuration    
    PC6     ------> USART6_TX
    PC7     ------> USART6_RX 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
    /* USART6 interrupt Init */
    HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART6_IRQn);
  /* USER CODE BEGIN USART6_MspInit 1 */
 
  /* USER CODE END USART6_MspInit 1 */
  }
}
 
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
{
 
  if(uartHandle->Instance==USART6)
  {
  /* USER CODE BEGIN USART6_MspDeInit 0 */
 
  /* USER CODE END USART6_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_USART6_CLK_DISABLE();
  
    /**USART6 GPIO Configuration    
    PC6     ------> USART6_TX
    PC7     ------> USART6_RX 
    */
    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_6|GPIO_PIN_7);
 
    /* USART6 interrupt Deinit */
    HAL_NVIC_DisableIRQ(USART6_IRQn);
  /* USER CODE BEGIN USART6_MspDeInit 1 */
 
  /* USER CODE END USART6_MspDeInit 1 */
  }
} 
 
/* USER CODE BEGIN 1 */
 
/* USER CODE END 1 */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

9 REPLIES 9

I'd probably use different buffers for RX/TX as with one you're likely to get stuff overwritten at some point.

If you have a second UART connected to a terminal, I would suggest forwarding data back/forth to the SIM800L, and confirm you can talk to it with AT commands.

Make sure the RX/TX sense of the connection is correct, ie output of modem goes to input of STM32

Make sure the SIM800L is powered up and functional, check if there is a pin state you can observe, ie POWERMON, TX, RING, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Scusi
Associate II

Thank for your fast reply.

I'm sure about these points

1) The module works fine. I tried it with an arduino one before the test with stm32;

2) The pins are connected correctly on the board;

3) I already use different buffers for RX e TX.

If i use two usarts, how can i use one with the terminal and other with the gms module? I use putty as terminal and when i open it i can only chose the com serial port and the baud rate. Any suggestions?

One STM32 UART connects to SIM800L, and second STM32 UART connects to a VCP/RS232 connection to a PC, you bridge the content between the two in a loop on the STM32. This will confirm end-to-end comms. Probably 115200 8N1, I'm not a SIMCOM guy, lean more TELIT here.

Once you have that working you can automate the comms on the STM32 interacting with the modem.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I've some news. I used a serial adapter to comunicate directly with the gsm module and it works fine. I used putty with 9600 8N1 which are the same settings i use on stm32. What can i do now?

I suspect that a possible problem is related to the TX voltage of the stm32. With arduino i read 5 volt on TX pin, with the serial adapter i read 3V on TX pin while on stm32 i read 60mV on TX pin. Could this be a problem? I said so, because the working voltage of sim800l in RX is between 2.5V and 2.8V.

Hardware problem - short, bad solder joint, check it by setting given pin as GPIO, toggling it and observing with an oscilloscope.

Software problem - incorrectly initialized GPIO, or disabled UART, read out and check the GPIO and UART registers.

JW

The gpio and the UART are correctly initialized because I use cubemx to setup them. I checked the GPIO and UART registers and i don't see nothing in reception because DR is empty and the pin of UART is 0. Obviously, if I use putty the DR value changes and the UART pin becomes 1. So the UART works correctly.

Aj.Chan
Associate

I have been trying to interface the same module with STM32L0 board and facing the exact same problem. I would like to know if there is any specific change I can do to make this work.

I have been seeing that the module would reply sometimes but not consistently. Looking forward for any solutions / suggestions on this matter.

What is your hardware, what have you done, what are the symptoms exactly and why do you think they be different from the expectations?

Start repeatedly transmitting "AT\n" and observe the Tx and Rx lines using oscilloscope/logic analyzer, and compare to what you receive in the mcu.

Note, that GSM modems have current consumption in pulses up to 2A, you have to have an adequate power supply for them.

JW

Zceli.1
Associate

Hello , I have same problem when try to get response SIM800C. And I have adequate power supply. SIM800C rx and tx pin have 2.8 volt. There is no response when MCU sends AT commands to module. Could you solve this problem after searching?