2025-01-23 02:12 AM - last edited on 2025-01-23 04:59 AM by SofLit
Hi,
I'm using STM32H745ZI for 4G LTE Communication Quectel EC200U-CN to transmit message using UART in Asynchronous mode, if I send continuous message then I'm getting this ................
AT
AT+CPIN?
AT+CMGF=1
AT+CMGD=1,4
AT+CSCS="GSM"
AT+CSCA="919849087001",145
ATE0
AT+CPIN?
AT+CMGS="+917981134448"
Hello from GSM!!
int main()
{
/*All initialize of UART and stuff*/
send4GSMS("Hello from GSM!!");
}
void send4GSMS(uint8_t *string)
{
//Enter CTRL+Z after sending the data, then the message will be sent
unsigned char asciiValue = 0x1A;
//Command to send a short message from TE to network
uint8_t sendMsg[30] = "AT+CMGS=\"+917981134448\""; //Configured mobile number
//sends the message from TE to network
sendATCommand(sendMsg);
LL_mDelay(1);
// Send the data
while (*string != '\0') {
// Transmit one character at a time
LL_USART_TransmitData8(USART3, *string++);
// Wait until transmit is complete
while (!LL_USART_IsActiveFlag_TC(USART3));
// Clear the TC flag for the next byte transmission
LL_USART_ClearFlag_TC(USART3);
}
// Send carriage return and line feed
LL_USART_TransmitData8(USART3, CR);
while (!LL_USART_IsActiveFlag_TC(USART3));
LL_USART_TransmitData8(USART3, LF);
while (!LL_USART_IsActiveFlag_TC(USART3));
LL_USART_TransmitData8(USART3, asciiValue);
while (!LL_USART_IsActiveFlag_TC(USART3));
LL_mDelay(10);
}
void MX_USART3_UART_Init(void)
{
LL_USART_InitTypeDef USART_InitStruct = { 0 };
LL_GPIO_InitTypeDef GPIO_InitStruct = { 0 };
LL_RCC_SetUSARTClockSource(LL_RCC_USART234578_CLKSOURCE_PCLK1);
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOD);
/**USART3 GPIO Configuration
PD8 ------> USART3_TX
PD9 ------> USART3_RX
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_8 | LL_GPIO_PIN_9;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_7;
LL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* USART3 interrupt Init */
NVIC_SetPriority(USART3_IRQn,
NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 0, 0));
NVIC_EnableIRQ(USART3_IRQn);
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
USART_InitStruct.BaudRate = 115200;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(USART3, &USART_InitStruct);
// USART3->BRR = 0x35B;
LL_USART_SetTXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
LL_USART_SetRXFIFOThreshold(USART3, LL_USART_FIFOTHRESHOLD_1_8);
LL_USART_DisableFIFO(USART3);
LL_USART_ConfigAsyncMode(USART3);
LL_USART_Enable(USART3);
/* Polling USART3 initialisation */
while ((!(LL_USART_IsActiveFlag_TEACK(USART3)))
|| (!(LL_USART_IsActiveFlag_REACK(USART3)))) {
}
/* Initializing the USART3 Receive Interrupt */
LL_USART_ReceiveData8(USART3);
LL_USART_EnableIT_RXNE_RXFNE(USART3);
}
void sendATCommand(const uint8_t *command)
{
// Clearing the rxBuffer before sending a new command
//(void) memset(&uart3_Buf, 0, sizeof(uart3_Buf));
// Send the command
while (*command != '\0') {
// Transmit one character at a time
LL_USART_TransmitData8(USART3, *command++);
// Wait until transmit is complete
while (!LL_USART_IsActiveFlag_TC(USART3));
// Clear the TC flag for the next byte transmission
LL_USART_ClearFlag_TC(USART3);
}
// Send carriage return and line feed
LL_USART_TransmitData8(USART3, CR);
while (!LL_USART_IsActiveFlag_TC(USART3));
LL_USART_TransmitData8(USART3, LF);
while (!LL_USART_IsActiveFlag_TC(USART3));
LL_mDelay(1);
}
2025-01-23 05:02 AM - edited 2025-01-23 05:18 AM
Hello,
This is not a STM32 question but it's related to the module you are using and the issue is not clear.
What do you mean by:
@Lucifer37 wrote:
if I send continuous message then I'm getting this ................
AT
AT+CPIN?
AT+CMGF=1
AT+CMGD=1,4
AT+CSCS="GSM"
AT+CSCA="919849087001",145
ATE0
AT+CPIN?
AT+CMGS="+917981134448"
Hello from GSM!!
What do you mean by "this"? the text in bold? is it an AT answer from the 4G modem?
2025-01-23 05:13 AM
@Lucifer37 wrote:if I send continuous message
What do you mean by that?
You should never just send continuous AT commands - you must always wait for the reply to one command before sending the next.
@Lucifer37 wrote:I'm using STM32H745ZI for 4G LTE Communication Quectel EC200U-CN
Please show your schematic.
See: How to write your question to maximize your chances to find a solution
2025-01-23 05:17 AM
@Andrew Neil wrote:
you must always wait for the reply to one command before sending the next.
Indeed.
2025-01-23 09:05 PM
Along with actual message "Hello from GSM!!" I'm getting AT commands in SMS
Actually I'm giving 10m sec delay sending any message via SMS, also I have given delays in AT commands, I increase the delays but still getting the AT commands along with the actual message.
2025-01-24 12:10 AM
Hello,
Did you try to interface the module with a PC and send commands with hyperterminal and see if it responds correctly to the commands?
2025-01-24 01:45 AM - edited 2025-01-24 02:11 AM
@Lucifer37 wrote:Along with actual message "Hello from GSM!!" I'm getting AT commands in SMS
Still not at all clear what you mean.
Where, exactly, are you "getting" these commands?
"getting" suggests receiving - but normally you would be sending the commands.
A diagram could be clearer; eg,
Microcontroller (STM32) Quectel +-------------+ +-------------+ | | SEND commands | | | TX +----------------------->+ RX | | | | | | RX +<-----------------------+ TX | | | RECEIVE responses | | +-------------+ +-------------+
(See this for how to post such a "text-diagram", or upload a picture, or your schematics)
@Lucifer37 wrote:I have given delays in AT commands, I increase the delays but still getting the AT commands along with the actual message.
Again, that's doomed to failure: you must to pay attention to the replies - not just rely blindly on arbitrary delays!
This is probably the commonest mistake people make with AT Commands:
https://www.avrfreaks.net/s/topic/a5C3l000000UYXnEAO/t146581?comment=P-1400752