• AVR Freaks

Helpful ReplyHot!USART Read stuck

Author
resilientboy
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2018/07/30 08:33:42
  • Location: 0
  • Status: offline
2020/07/02 00:40:30 (permalink)
0

USART Read stuck

Hi i'm building a remote controller between 2 pic16f19197
While i'm running i've discovered a weird stuation.
The system was running and i thought it was too good to be true but then i guess it really was.

I've used MCC to get USART functions.
I just read and send an ACK data back.
But the debug shows that %5 of the time Pic gets stuck at the start of read function.
It also of course blocks all other functions of the Pic.
 
 
rxData = EUSART2_Read();  //Calls the malfunctioning function
 
 
//This code is from MCC I didn't change anything at all
uint8_t EUSART2_Read(void)      //Stuck Here and goes nowhere doesn't even go into the function itself.
{
while(!PIR3bits.RC2IF)
{
}
eusart2RxLastError.status = 0;

if(1 == RC2STAbits.OERR)
{
// EUSART2 error - restart
RC2STAbits.CREN = 0;
RC2STAbits.CREN = 1;
}
return RC2REG;
}
 
Also since i've discovered this I've modified the sender to send "0x10" line feed until it comes out of it.
And it seems after 24 bytes of "line feed" it gets unstuck and continues to work.
 
Any ideas would be great as i'm out of any.
#1
du00000001
Just Some Member
  • Total Posts : 3851
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: USART Read stuck 2020/07/02 10:05:03 (permalink) ☄ Helpfulby resilientboy 2020/07/02 11:45:21
+1 (1)
You'd better check for the IF flag prior calling the read function if you cannot afford to wait for the next character to be received.
This read function is made to wait for a character to arrive. Unless you have a masive mismatch of baud rates, this function doesn't differentiate between characters. But maybe the rest of your software (not shown) does.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
resilientboy
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2018/07/30 08:33:42
  • Location: 0
  • Status: offline
Re: USART Read stuck 2020/07/02 11:44:30 (permalink)
0
 
Sorry for the Missing call code.
 
while (EUSART2_is_rx_ready() || Data_Start) {
TMR1_WriteTimer(0);
TMR4_WriteTimer(0);
Screen_Serial_Receive();
}


Copying here i found the ridiculous mistake i made :D
I called the function if Data has started pouring but didn't check again if there actually was data to be read afterwards.
My bad.
 
Initially it was as
if(EUSART2_is_rx_ready())
...

But after some time i saw that i was losing some packages then decided my long cycle making me miss packages so made it a While loop if Data started.
And yes the code itself differentiates bytes as STX ETX or CRC so after STX it makes Data_Start = 1
After that if it misses ETX and sender stops i guess that's game over :) we're stuck forever.

Thanks it helped a ton.
 
Also i learned now that if u call serial read function it waits for data. Didn't know that i always thought it would read as null.
post edited by resilientboy - 2020/07/02 11:51:28
#3
BroadwellConsultingInc
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2020/06/09 06:07:55
  • Location: 0
  • Status: offline
Re: USART Read stuck 2020/07/02 12:15:53 (permalink)
0
Are you sure that's what's happening?  Or is the tool chain treating the function name and first line as the same thing?  Go into disassembly view and see if it's actually sitting on a bit test or similar instruction pointing at PIR3bits.RC2IF .   It could be that it's doing exactly what it is supposed to and RC2IF is never getting set.
#4
resilientboy
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2018/07/30 08:33:42
  • Location: 0
  • Status: offline
Re: USART Read stuck 2020/07/02 12:36:34 (permalink)
0
BroadwellConsultingInc
Are you sure that's what's happening?  Or is the tool chain treating the function name and first line as the same thing?  Go into disassembly view and see if it's actually sitting on a bit test or similar instruction pointing at PIR3bits.RC2IF .   It could be that it's doing exactly what it is supposed to and RC2IF is never getting set.


Okay i'll check it in the morning, as all my equipment is in my workplace.
Thanks for all the help.
#5
Gort2015
Klaatu Barada Nikto
  • Total Posts : 3984
  • Reward points : 0
  • Joined: 2015/04/30 10:49:57
  • Location: 0
  • Status: offline
Re: USART Read stuck 2020/07/02 15:41:54 (permalink)
+1 (1)
0x10
That is not Line Feed, maybe why you are getting errors.

MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
https://www.youtube.com/watch?v=Iu1qa8N2ID0
+ ST:Continues, "What Ships are Made for", Q's back.
#6
ric
Super Member
  • Total Posts : 28009
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: USART Read stuck 2020/07/02 15:46:27 (permalink)
0
Gort2015
0x10
That is not Line Feed, maybe why you are getting errors.

Indeed, maybe confused with decimal 10, the actual value of LF, so 0x0A.
0x10 is DLE, I thought maybe this was an attempt to send XON, but that is code 0x11.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#7
resilientboy
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2018/07/30 08:33:42
  • Location: 0
  • Status: offline
Re: USART Read stuck 2020/07/03 00:40:34 (permalink)
+1 (1)
Gort2015
0x10
That is not Line Feed, maybe why you are getting errors.


ric
Gort2015
0x10
That is not Line Feed, maybe why you are getting errors.

Indeed, maybe confused with decimal 10, the actual value of LF, so 0x0A.
0x10 is DLE, I thought maybe this was an attempt to send XON, but that is code 0x11.
 



Thanks. You guys are very observant.
My bad. I meant 10 decimal.
But the mistake was from my part. Fixed it after checking if there is data before reading.
#8
Jump to:
© 2020 APG vNext Commercial Version 4.5