CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC24EP512 - Grabbing serial characters in a loop

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PIC24EP512 - Grabbing serial characters in a loop
PostPosted: Fri Oct 25, 2024 6:21 pm     Reply with quote

Device: PIC24EP512GP806
Compiler: 5.026 (very very old)

Hi guys,

I know this sounds very simple but I've always programmed INT_RDA by grabbing characters upon each interrupt and storing it in a buffer upon every interrupt.

I now am programming a display that sometimes returns plain text characters and sometimes some HEX data like \x00\x00\x00\xff\xff\xff\x88\xff\xff\xff. This is the power-up message for the display.

The problem is that when it's text data, it starts with # and ends with *. That's easy to figure-out... the data gets accumulated as the interrupt is generated then process later when * is found. And it works as expected.

But when it's hex data, it just screws-up everything because, although all responses end with \xFF\xFF\xFF, some may contain other \xFF\xFF\xFF in the middle like the one I indicated above which is 10 bytes long. Others can be 6, others 4 like \x66\x00\x02\xFF\xFF\xFF or \x02\xFF\xFF\xFF.

So I was thinking that perhaps I could use a simple while loop like this:

while( kbhit( UART_DISPLAY ) == TRUE )
{
ReceiveBuffer[RxCharacterCounter ] = (unsigned char) fgetc( UART_DISPLAY );
RxCharacterCounter ++;
}

However, it appears that it grabs something but not what I am expecting.... but I do see the proper data get sent by the display on my logic analyzer....

Therefore, my question is: when using a while loop with kbhit() inside an interrupt, is there anything in particular I should do? Like clear the interrupt or whatever?

I'm a bit confused and been working with these pics for a decade but never attempted to grab all characters in a loop inside the as soon as the first interrupt arrives.

I do disable the interrupt when it is entered and re-enable it when exiting.

Not sure if it makes sense?

Thanks!

Ben
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Fri Oct 25, 2024 7:37 pm     Reply with quote

Alrighty, if you have an answer, no problem but I found a solution.

When the display powers-up and sends me the long hex string \x00\x00\x00\xff\xff\xff\x88\xff\xff\xff, I just saw that this is actually programmable so I changed it to something simpler within my own protocol #\x99* and it works.

But if you still have input on my question, then maybe it will help others and I may also benefit from it.

Cheers!

Ben
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Sat Oct 26, 2024 4:11 am     Reply with quote

On the PIC24/30/33 the serial actually has a 4 or 8 character FIFO.
It also will not interrupt again, if you leave the interrupt handler with
characters in this FIFO 'unread'. On the PIC16/18, it will interrupt if
you do this.
So on these later chips you must repeat the read if more characters
are waiting.
Look at:
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=59548&highlight=pic24+intrda
[/url]

Now you don't test at the start of the loop (this is a waste of time), but
at the end as I show in this thread.

However sepaately, I am worried by what you show. Problem is what
prevents RxCharacterCounter from growing beyond the size of your
buffer?. Nothing shown. Mad
If it does, your write will start to write into storage locations beyond
the buffer. Result disaster. You must always make sure when using
pointers and arrays, that the index is limited to the available space.

No, you do not have to disable/re-enable the interrupt,
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Oct 27, 2024 6:37 pm     Reply with quote

re: Compiler: 5.026 (very very old)

I guess that's why I'm a 'dinosaur'.....My first PCM was 2.534

Thanks for making an old guy ,feel even older Sad
Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Mon Oct 28, 2024 1:48 am     Reply with quote

Why?.
It was only yesterday... Very Happy
Must admit I was glancing back at my code archives. Have some code there
dated to just before the millennium, using CCS. The stuff before that used
a different compiler. The really early stuff was all in assembler. I remember
a few years ago, when MicroChip did a history of the PIC, i had to point out
to them that they had their launch date wrong, since I had a project built
nearly a year before they claimed to have launched the processor....
Recent times. Smile
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Nov 06, 2024 10:53 pm     Reply with quote

Ttelmah wrote:
Why?.
I remember a few years ago, when MicroChip did a history of the PIC, i had to point out to them that they had their launch date wrong, since I had a project built nearly a year before they claimed to have launched the processor....
Recent times. Smile


Very Happy

Speaking of archives -- I recently took a pic of some windows EPROM PICs to share in a FB group...

And we laughed and chuckled at the age of the PICs and us.

Laughing [/img]
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group