cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 with simcom A7672S

sreedharan1196
Associate II
#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
21 REPLIES 21

i am observing my output on Serial port of arduino ide, using the USAR2

how to d the turning Echo on and off

So you're missing the first half  (~40 characters) of that string, YES , my buffer size is big enough


@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

 


@sreedharan1196 wrote:

i am observing my output on Serial port of arduino ide, using the USAR2


So why are you posting under 'STM32CubeIDE' when you're using the Arduino IDE - not STM32Cube?

🤔

 

What creates that "output"?

It seems to be a combination of the output from the STM32 to the A7672S, and the output from the A7672S back to the STM32?

Are you sure that process is working properly?

 


@sreedharan1196 wrote:

 YES , my buffer size is big enough


How have you verified that?

that my older Code, plz find my new set of code , in that only i am getting that issues, also for Some AT commands i dint receive full OK ,jus got only K and O

 

void  parseCmd(char *command, int delay)
{
// HAL_UART_Init(&huart1);
 
char rxdata[100];
memset(rxdata, 0, sizeof(rxdata));
HAL_UART_Transmit(&huart1,(uint8_t*)command,strlen(command),delay);
     HAL_UART_Receive(&huart1,rxdata,sizeof(rxdata),delay);
     HAL_UART_Transmit(&huart2,rxdata,sizeof(rxdata),1000);
 
     //HAL_UART_DeInit(&huart1);
}
 
void ExecuteHTTPGetRequest()
{
parseCmd("ATE\r\n",2000);
parseCmd("AT+CSQ\r\n",2000);
parseCmd("AT+CREG?\r\n",2000);
parseCmd("AT+CGREG?\r\n",5000);
parseCmd("AT+CEREG=1\r\n",5000);
parseCmd("AT+CPSI?\r\n",2000);
parseCmd("AT+CGACT=1,1\r\n",10000);
parseCmd("AT+CGATT=1\r\n",2000);
parseCmd("AT+CGREG?\r\n",2000);
sprintf(ATcommand,"AT+CGDCONT=1,\"IP\",\"%s\"\r\n",apn);
parseCmd(ATcommand,4000);
parseCmd("AT+HTTPINIT\r\n", 12000);
parseCmd("AT+HTTPACTION=1\r\n",10000);
parseCmd("AT+HTTPTERM\r\n",5000);
}

 

 

void  parseCmd(char *command, int delay)
{
// HAL_UART_Init(&huart1);
 
char rxdata[100];
memset(rxdata, 0, sizeof(rxdata));
HAL_UART_Transmit(&huart1,(uint8_t*)command,strlen(command),delay);
     HAL_UART_Receive(&huart1,rxdata,sizeof(rxdata),delay);
     HAL_UART_Transmit(&huart2,rxdata,sizeof(rxdata),1000);
 
     //HAL_UART_DeInit(&huart1);
}
 
void ExecuteHTTPGetRequest()
{
parseCmd("AT\r\n",2000);
parseCmd("AT+CSQ\r\n",2000);
parseCmd("AT+CREG?\r\n",2000);
parseCmd("AT+CGREG?\r\n",5000);
parseCmd("AT+CEREG=1\r\n",5000);
parseCmd("AT+CPSI?\r\n",2000);
parseCmd("AT+CGACT=1,1\r\n",10000);
parseCmd("AT+CGATT=1\r\n",2000);
parseCmd("AT+CGREG?\r\n",2000);
sprintf(ATcommand,"AT+CGDCONT=1,\"IP\",\"%s\"\r\n",apn);
parseCmd(ATcommand,4000);
parseCmd("AT+HTTPINIT\r\n", 12000);
parseCmd("AT+HTTPACTION=1\r\n",10000);
parseCmd("AT+HTTPTERM\r\n",5000);
}
 
that my older Code, plz find my new set of code , in that only i am getting that issues, also for Some AT commands i dint receive full OK ,jus got only K and O

yes verified with the buffer size , i had also attached full code on previous, we have interfaced the stm32 with A7672s with the level shifter,  so the At commands from STM32 will send to level shifters RX and TX and the level shifter will tranmsit that to A7672S, 

 

It is difficult to time the receive. I guess for "proper" response from the modem  uart port without missing characters etc, you have to receive the characters via ISR. implement UART_RECEIVE_IT, in the ISR set a flag when the buffer is full, check the flag in the main code and print.

Did you send at+httpsend \r\n command also?