Skip to main content
Associate III
May 21, 2024
Question

stm32 with simcom A7672S

  • May 21, 2024
  • 5 replies
  • 6993 views
#include "main.h"
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar(void)
 
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
 
PUTCHAR_PROTOTYPE
{
    HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
    return ch;
}
 
GETCHAR_PROTOTYPE
{
    uint8_t ch = 0;
    __HAL_UART_CLEAR_OREFLAG(&huart2);
    HAL_UART_Receive(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
    return ch;
}
 
int id = 212200;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_USART2_UART_Init(void);
 
void parseCmd(char* command, int timeout);
 
int main(void)
{
  setvbuf(stdin, NULL, _IONBF, 0);
 
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
 
  HAL_GPIO_WritePin(Enable_key_GPIO_Port, Enable_key_Pin, GPIO_PIN_SET);
  HAL_Delay(2000);
  HAL_GPIO_WritePin(Power_key_GPIO_Port, Power_key_Pin, GPIO_PIN_RESET);
  HAL_Delay(2000);
 
  printf("Sending AT commands...\n");
 
  while (1)
  {
  char strAT[50];
  parseCmd("AT\r\n", 1000); //Check AT
  parseCmd("ATE1\r\n", 1000);
  parseCmd("AT+CSQ\r\n", 1000);
  parseCmd("AT+CPIN?\r\n", 1000);
  parseCmd("AT+CREG=1\r\n", 1000);
  parseCmd("AT+CGREG?\r\n", 1000);
  parseCmd("AT+CGATT=1\r\n", 1000);
  parseCmd("AT+QIFGCNT=0\r\n", 1000);
  parseCmd("AT+QICSGP=1,\"WWW\",\"\",\"\"\r\n", 1000);
  parseCmd("AT+QIREGAPP\r\n", 1000);
  parseCmd("AT+QIACT\r\n", 1000);
  HAL_Delay(2000);
  sprintf(strAT, "AT+QHTTPURL=%d,%d", str_len, 180);
  //Serial.println(strAT);
  printf("The string %s",strAT);
  parseCmd(strAT, 1000);
  parseCmd(json_1, 3000);
  parseCmd("AT+QHTTPPOST=60", 3000);
  parseCmd("AT+QHTTPREAD", 3000);
  parseCmd("AT+QIDEACT", 1000);
 
void parseCmd(char* command, int timeout)
{
    HAL_Delay(timeout);
    char rxdata[300];
    memset(rxdata, 0, sizeof(rxdata));
    // Transmit command over UART1
    HAL_UART_Transmit(&huart1, (uint8_t*)command, strlen(command), timeout);
    // Receive response over UART1
    HAL_UART_Receive(&huart1, (uint8_t *)rxdata, sizeof(rxdata), timeout);
    // Transmit response over UART2
    HAL_UART_Transmit(&huart2, (uint8_t *)rxdata, strlen((char *)rxdata), timeout);
}
 
OUTPUT:
10:29:51.329 -> AT
10:29:51.329 -> OK
10:29:53.295 -> ATE1
10:29:53.295 -> OK
10:29:54.323 -> AT
 
i am using the above AT commands in simcom A7672S ,i am unable to get the proper response from the simcom, may, i know what the issues i am facing, Guide me with the issues i am facing her and help me to sort out this issues

    5 replies

    Senior III
    May 23, 2024

    Firstly chek if the module is able to receive call from another mobile. JUST call that number and check ring back tone. Connect the module to computer using a USB to ttl converter and chek if the module behaves properly.  ATD your number to initiate a  call from mobile.  AT+CSQ for signal strength etc..

     

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    Associate III
    May 23, 2024

    verify with it, its working properly, for sms, and Call, also for all other AT commands, but the only issues is 

    sprintf(ATcommand,"AT+HTTPPARA=\"URL\",\"http://iot.salieabs.in:5003/api/postDeviceDatadev=2122001&mr=108&warn=Done\"\r\n");

     

    for the above AT commands i am getting only the below response, the response is ok thats not the issues, issue is for User interface i am not getting the full response 

     

    output:

    11:21:33.298 -> ceData?dev=2122001&mr=108&warn=Done"
    11:21:33.298 -> OK

     

     

    Senior III
    May 23, 2024

    Looks like you have enabled local echo, other wise I guess the response will be "OK", what is the expected output?

     

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    Associate III
    May 23, 2024

    thanks for the response, i clear that issues, now i am facing an issue with response received, i am able to get only the half the  response code from the simcom, what tha issues with the above code, help me to short out it

     

    char ATcommand[200];

    void parseCmd(char *command, int http_time)
    {
    char rxdata1[1000];
    memset(rxdata1, 0, sizeof(rxdata1));

    // printf("The AT : %s\r\n",command);

    // Transmit command over UART1
    HAL_UART_Transmit(&huart1, (uint8_t*)command, strlen(command),http_time);

    // Receive response over UART1
    HAL_UART_Receive(&huart1, (uint8_t *)rxdata1, sizeof(rxdata1),http_time);

    // Transmit response over UART2
    HAL_UART_Transmit(&huart2, (uint8_t *)rxdata1, strlen(rxdata1),100);

    }

    sprintf(ATcommand,"AT+HTTPPARA=\"URL\",\"http://iot.salieabs.in:5003/api/postDeviceDatadev=2122001&mr=108&warn=Done\"\r\n");
    parseCmd(ATcommand,2000);

     

    output:

    11:21:33.298 -> ceData?dev=2122001&mr=108&warn=Done"
    11:21:33.298 -> OK

     

    Andrew Neil
    Super User
    May 23, 2024

    On debugging serial comms:

    https://www.avrfreaks.net/s/topic/a5C3l000000UaFXEA0/t153137?comment=P-1212903 

     

    Please use this button to properly post source code:

    AndrewNeil_0-1716454761104.png

     

    #DebugSerialComms

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Andrew Neil
    Super User
    May 23, 2024

    @sreedharan1196 wrote:
     
      parseCmd("AT\r\n", 1000); //Check AT

    Note that the standard AT command terminator is just CR - not CRLF.

     


    @sreedharan1196 wrote:
    10:29:53.295 -> ATE1
    10:29:53.295 -> OK

    Why are you turning Echo on?

    This means that the modem will send back every single character you send to it.

    How are you observing this "output" ?

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Associate III
    May 23, 2024

    how to d the turning Echo on and off

    Andrew Neil
    Super User
    May 23, 2024

    @sreedharan1196 wrote:

    how to d the turning Echo on and off


    You're doing it right here:

     


    @sreedharan1196 wrote:
     
    10:29:53.295 -> ATE1
    10:29:53.295 -> OK

     

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Senior III
    May 23, 2024

    Sorry, HTTPSEND was for 7672,  Can you try AT+HTTPREAD and AT+HTTPHEAD  , I am referring to

    https://www.ktron.in/wp-content/uploads/2023/03/A76XX-Series_AT_Command_Manual_V1.06-4.pdf

     

    but anyway please try to do the reading from UART_RECEIVE_IT, interrupt, so that you will not miss characters

     

    "If you feel a post has answered your question, please click ""Accept as Solution""."