View previous topic :: View next topic |
Author |
Message |
nailuy
Joined: 21 Sep 2010 Posts: 159
|
Example of sending / receiving UART |
Posted: Sun Nov 26, 2017 10:41 am |
|
|
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
|
|
Posted: Sun Nov 26, 2017 11:23 am |
|
|
Why so complicated ? Use the Ex_sisr.c example code to receive bytes
in the slave. |
|
|
nailuy
Joined: 21 Sep 2010 Posts: 159
|
|
Posted: Sun Nov 26, 2017 1:50 pm |
|
|
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
|
|
Posted: Sun Nov 26, 2017 2:18 pm |
|
|
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
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Nov 26, 2017 3:37 pm |
|
|
...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
|
|
Posted: Sun Nov 26, 2017 3:58 pm |
|
|
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
|
|
Posted: Mon Nov 27, 2017 2:03 am |
|
|
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
|
|
Posted: Mon Nov 27, 2017 3:37 pm |
|
|
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
|
|
Posted: Mon Nov 27, 2017 5:48 pm |
|
|
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 |
|
|
|