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

Example of sending / receiving UART

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



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

Example of sending / receiving UART
PostPosted: Sun Nov 26, 2017 10:41 am     Reply with quote

Hy
I want to send 3 bytes from master and receive in slave all 3 bytes in single pack.

in master:
Code:

...
putc(110);
putc(31);
putc(131);
while(TRMT==0);{}
...


in slave:
Code:
...
while(RCIDL==0);{}
if(kbhit()) {x=getc();}
while(RCIDL==0);{}
if(kbhit()) {y=getc();}
while(RCIDL==0);{}
if(kbhit()) {z=getc();}

...

x,y,z, are not expected results in slave.
Have anybody an example for both?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 11:23 am     Reply with quote

Why so complicated ? Use the Ex_sisr.c example code to receive bytes
in the slave.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 1:50 pm     Reply with quote

hy
sorry I look at that example but I'm not understand how is working.
I think is difficult for me that example now.
I look if can make work without interrupt.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 2:18 pm     Reply with quote

getc, by default waits for a character to arrive. You can get rid of all your tests, and just have three getc calls....

You may well be getting hung because of using RCIDL. You don't tell us what chip you have, but on some PIC's this does not work.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 3:20 pm     Reply with quote

Dear Ttelmah
is PIC16F1827 same early project
http://www.ccsinfo.com/forum/viewtopic.php?t=56803

Now I have new steps, but I have problems for receiving 3 bytes of data.
temtronic



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

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 3:37 pm     Reply with quote

...the UART probably has a 2 character 'buffer' ( most PICs do..) so the PIC UART will 'lockup' when the 3rd comes in... you need to look at the ex_sisr.c example .
You should post your complet program... I'm thinking you haven't got 'ERRORS' added to teh #use RS232(...options...)

Jay
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 3:58 pm     Reply with quote

I can't post entire code
I found preprocessor directive
#int_xxx
#INT_RDA
#INT_RDA0
#INT_RDA1
#INT_RDA2
I will test and try to work with them.
I will be back with reply in couple of days.
Best regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 2:03 am     Reply with quote

As has already been said, look at EX_SISR.

Starting to spray interrupt declarations around, is a sure way of stopping your code working. Especially INT_XXX which doesn't exist.
You haven't told us what chip you are using, but unless you have one with four built in UARTs, you are making complexities that won't help.
You must never have an interrupt fully enabled (it and GLOBAL), without a handler present. ex_sisr.c shows haw to handle a serial interrupt.
A search here will find 'how this works' described (many times), but a search online for 'circular buffer', may help.

Seriously, the key thing with programming is to take little steps, and understand how they work at each point. If you can't understand ex_sisr, stop and study it till you do.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 3:37 pm     Reply with quote

I found simple working solution:

#int_rda
void serial_isr() {
RX_IN[i]=getc();
i++;
}

what is difference between?

void serial_isr()
and
void rda_isr()
temtronic



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

View user's profile Send private message

PostPosted: Mon Nov 27, 2017 5:48 pm     Reply with quote

None really, they are both just 'names' for functions.

By their names though...

serial_isr() appears to be an interrupt function for some kind of serial data. Note that 'serial data' could be 1 byte, 22bits or 123 words NOT just 8 bit data.

rda_isr() appears to be an interrupt function utilizing the UART peripheral of a PIC. Without more details it's really hard to say for certain though !

These are just 'guesses', without seeing all the code, of course.
Jay
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