STM32L476VGT UART4 with GSM module SIM7000E
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-26 3:18 AM
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 ?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-16 12:09 AM
I used USART1 by using the pins PB6 and PB7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-26 3:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-26 6:40 AM
Thank you for your response, but I didn't get the second part "Parsing serial output ...", can you explain more plz ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-26 11:29 AM
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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-03-26 10:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-16 12:09 AM
I used USART1 by using the pins PB6 and PB7
