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.