cancel
Showing results for 
Search instead for 
Did you mean: 

regarding issues in Stm32lo51 with simcom a7670c

sree1996
Associate


#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#define GETCHAR_PROTOTYPE int __io_getchar(void)

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */

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;
}

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */

void sendATCommand(char *command);
void Clear_UART_Buffer(UART_HandleTypeDef *huart);

/* 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 */
setvbuf(stdin, NULL, _IONBF, 0);
/* 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_USART1_UART_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */

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");

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
sendATCommand("AT\r\n");
sendATCommand("AT+CPSI?\r\n");
sendATCommand("AT+CGDCONT=1,\"IP\",\"WWW\"\r\n");
sendATCommand("AT+CGACT?\r\n");
sendATCommand("AT+CGACT?\r\n");
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
}

void Clear_UART_Buffer(UART_HandleTypeDef *huart)
{
uint8_t clear_buffer[100];
memset(clear_buffer, 0, sizeof(clear_buffer));
HAL_UART_Transmit(huart, clear_buffer, sizeof(clear_buffer),1000);
}

void sendATCommand(char* command)
{
HAL_Delay(1000);
char rxdata1[300];
memset(rxdata1, 0, sizeof(rxdata1));

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

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

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


// Clear UART buffers
Clear_UART_Buffer(&huart1);
Clear_UART_Buffer(&huart2);
}

 

while using the above code, the At commands is transmitting good, but unable to get the proper response from the, it print the response with some other set of words, can u guide me with the issues i am making, guide me clear the error 

 

0 REPLIES 0