UART Receive code is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-03 3:17 AM
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;
}
Solved! Go to Solution.
- Labels:
-
STM32F1 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-03 5:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-03 3:56 AM
>> 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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-03 4:03 AM
All connections are fine, please check below function. will it works?
- 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;
- }
Thanks for reply Javier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-03 5:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-02-05 11:49 PM
Thank you gbm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-09-29 1:06 AM
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?
