Skip to main content
Siva Ram
Associate II
February 3, 2023
Solved

UART Receive code is not working.

  • February 3, 2023
  • 4 replies
  • 3108 views

I am using STM32F103C8 MCU and Trying to communicate with Quectel EC200U-CN 4G module and i am not getting data through UART2 Receive pin.

Please go through my code and suggest me

void USART2_IRQHandler(void){
	if ((USART2->SR & USART_SR_RXNE) != RESET){
		GSM_buf[GSM_indx] = USART2->DR;
		GSM_indx++;
		while(!(USART2->SR & USART_SR_TC));
	}
	if(GSM_indx >= (BUF_SIZE-1))
		GSM_indx = 0;
}

This topic has been closed for replies.
Best answer by gbm

No. You shouldn't wait for TC flag in the ISR. It has nothing to do with UART reception.

And this:

for(int i = 0;i<500000;i++);

may be optimized to nothing, so no delay will be provided.

4 replies

Javier1
Principal
February 3, 2023

>> go through my code

Thats the equivalent to going to your baker and demanding free bread.

did you checked uart pins TX and RX are properly swapped with your quectel module?

hit me up in https://www.linkedin.com/in/javiermuñoz/
Siva Ram
Siva RamAuthor
Associate II
February 3, 2023

All connections are fine, please check below function. will it works?

  1. void USART2_IRQHandler(void){
  2. if ((USART2->SR & USART_SR_RXNE) != RESET){
  3. GSM_buf[GSM_indx] = USART2->DR;
  4. GSM_indx++;
  5. while(!(USART2->SR & USART_SR_TC));
  6. }
  7. if(GSM_indx >= (BUF_SIZE-1))
  8. GSM_indx = 0;
  9. }

Thanks for reply Javier.

gbm
gbmBest answer
Lead III
February 3, 2023

No. You shouldn't wait for TC flag in the ISR. It has nothing to do with UART reception.

And this:

for(int i = 0;i<500000;i++);

may be optimized to nothing, so no delay will be provided.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Siva Ram
Siva RamAuthor
Associate II
February 6, 2023

Thank you gbm

Visitor II
September 29, 2023

Could you send me the overall code for sending and receiving the msg from EC200U-cn I have tried with At commands sending through the UART,which one is the crt way?