cancel
Showing results for 
Search instead for 
Did you mean: 

UART Receive code is not working.

Siva Ram
Associate II

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;
}

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Lead III

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.

View solution in original post

5 REPLIES 5
Javier1
Principal

>> 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?

we dont need to firmware by ourselves, lets talk
Siva Ram
Associate II

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
Lead III

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.

Thank you gbm

SandeepK
Associate

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?