cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476VGT UART4 with GSM module SIM7000E

Moughit
Associate III

Hello,

I'm trying to connect SIM7000E with STM32L476VGT by using UART4 (PA0 as Tx and PA1 as Rx)

I'm already using USART2 to show messages in RealTerm and I can't use the other UARTs because I can't find the pins on the board.

This is the code I'm trying to run :

HAL_UART_Transmit(&huart2, (uint8_t*)"Start program\r\n", sizeof "Start program\r\n", 1000);

   char RxTx_Buffer[30] = "";

   HAL_UART_Transmit(&huart4, (uint8_t*)"ATE0\r\n", sizeof "ATE0\r\n", 100);

   HAL_UART_Receive(&huart4, (uint8_t*)RxTx_Buffer, 20, 500);

   

if(strstr(RxTx_Buffer, "OK") != NULL)

   {

      HAL_UART_Transmit(&huart2, (uint8_t*)"Ok\r\n", sizeof "Ok\r\n", 1000);

   }

   else if(strstr(RxTx_Buffer, "ERROR") != NULL)

   {

      HAL_UART_Transmit(&huart2, (uint8_t*)"Error\r\n", sizeof "Error\r\n", 1000);

      AT_ERROR_FLAG = true;

   }

   else

   {

      HAL_UART_Transmit(&huart2, (uint8_t*)"None\r\n", sizeof "None\r\n", 1000);

   }

The result I'm always getting is "None" and I don't know why it's not working.

Can someone plz help me with this ?

1 ACCEPTED SOLUTION

Accepted Solutions
Moughit
Associate III

I used USART1 by using the pins PB6 and PB7

View solution in original post

5 REPLIES 5
KnarfB
Principal III

For debugging, you should echo all huart4 responses to huart2, not only say "None."

Also note that sizeof as in sizeof "ATE0\r\n" is wrong because it includes the trailing '\0' char which must not be sent. strlen is your friend.

Parsing serial output can be tedeious, escpecially if you are out of sync and need to re-sync. I would suggest a line by line parser (scanner) first which only cares for newlines and a second "semantic parser" layer which inteprets each line response.

Thank you for your response, but I didn't get the second part "Parsing serial output ...", can you explain more plz ?

Use subroutines so you don't keep repeating stuff, use strlen() to properly determine the string length.

The modem may take some time to respond, you need to be waiting for data in an interrupt so you don't miss anything while sending, and you need to process the data received, over a few hundred milliseconds after sending to get the response.

This is like tennis, there is some flight time in the back-n-forth interaction.

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

I used USART1 by using the pins PB6 and PB7