View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Problem with USART communication between 2 x 18F66J60 |
Posted: Fri May 03, 2013 9:01 am |
|
|
Hi! I have 2 18F66J60. Without any problems I`m transmiting data from master to slave, but I don`t recieve data from the slave. Here is my code:
Master:
Code: |
#include <18F66J60.h>
#FUSES HS,NOWDT
#use delay(clock=10M)
#use RS232(STREAM=LAN,BAUD=9600,XMIT=PIN_F1,RCV=PIN_F2,PARITY=N,BITS=8,ERRORS,STOP=1)
void main()
{
int d=0;
while(1)
{
if(kbhit())
{
d=getc(LAN);
}
}
}
|
SLAVE:
Code: |
#include <18F66J60.h>
#FUSES HS,NOWDT
#use delay(clock=25M)
#use RS232(STREAM=first,BAUD=9600,XMIT=PIN_B1,RCV=PIN_B0,PARITY=N,BITS=8,ERRORS,STOP=1)
void main()
{
while(1)
{
putc(5,first);
}
}
|
I have a physical connection. I don`t think it`s a hardware problem.
Can you tell me what I`m missing?
Thanks! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri May 03, 2013 9:47 am |
|
|
This line sends a binary 5 not the ascii number 5.
try this:
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Fri May 03, 2013 10:10 am |
|
|
Data format is not a problem. I don't receive anything on master.
I don't enter in kbhit().... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri May 03, 2013 10:27 am |
|
|
OK, if you want to receive raw binary no problem from me.
Why did you specify a stream for getc but not kbhit? _________________ Google and Forum Search are some of your best tools!!!! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Fri May 03, 2013 11:03 am |
|
|
I`ve missed that! I`ll add it and see what`s gonna happen! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Fri May 03, 2013 2:13 pm |
|
|
Now everything works fine! I can`t explain it.... |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri May 03, 2013 2:39 pm |
|
|
Actually easy to explain. If you specify a stream in USE RS232 you have to
include it in all RS232 functions that will use that stream otherwise the output
defaults to system console (stdout). If you take the stream definition out of USE
RS232 it defaults to stdout as well. You don't need a stream at all
unless you are going to define another RS232 connection. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Thu May 09, 2013 10:13 am |
|
|
There is one more thing! I transmitted a few bytes but I didn`t realized the transmitted data is received incorrectly.
When I transmit for example 55(putc(55,LAN)) on the other side I receive for different data everytime but not 55!
What`s happening here? The controllers has different oscillators. Could it be the problem?
Thanks! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Thu May 09, 2013 11:13 am |
|
|
Yes, a difference in transmit speed between the two PICs can cause this... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9224 Location: Greensville,Ontario
|
|
Posted: Thu May 09, 2013 1:04 pm |
|
|
Providing both PICs have crystals or oscillator 'cans', it should be the cause...
However my concern is the lack of incoming buffering of the data!
As posted the 'slave' is free running...meaning it is continously sending data...and without the 'master' having an ISR with buffer,it can't keep up with the data.
CCS does supply examples of both transmit and receive ISR buffering( ex_sisr.c for one...)
as an aside...
To me though the use of 'master' and 'slave' is wrong, as traditionally the 'slave' would only send data when requested from the 'master'.
hth
jay |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Mon May 13, 2013 11:08 am |
|
|
I have unexpected problem! I`m transmitting data from "master" to "slave", but the "master" can`t recieve even a single byte from the "slave". I switched XMIT and RCV pins to check the connections and agian - slave recieves data from the master, but the master doesn`t recieve anything.
What can cause this?
Just for temtronic: I`m using communication protocol in which master demands data with sending special byte to the slave and the slave responds with special byte when it`s ready to transmit.
Thanks! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9224 Location: Greensville,Ontario
|
|
Posted: Mon May 13, 2013 11:14 am |
|
|
You should post your curent programs.The original 'master' only receives data, never transmits.
Also try using a PC terminal program as the 'slave' to confirm that the 'master' is transmitting and receiving correctly. If it does then your 'slave' code has aproblem.
hth
jay |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Mon May 13, 2013 11:26 am |
|
|
OK! I tried with different controller connected to the master. It seems my slave 18F66J60 is not transmitting. The debugger and programmer(PIC kit 3) is working fine, so I think the microcontroller is power supplied correctly. It recieves data from the master - so it`s working. I change the wires as I said before and there was no change. I tried with different pins - no change.
Can you tell me what can cause this? What can disturb the transmition??
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon May 13, 2013 2:54 pm |
|
|
Two basic thinsg:
1) Ground connection. Remember you need a ground as well as the data lines.
2) Clock rate. Do the basic 'flash an LED' test on each chip and verify that it flashes at the correct rate. If not, then the chip is not running at the speed you think. Could be something like a wire whisker stopping the oscillator from running, and the chips in most cases will drop 'back' to their internal oscillator.
Best Wishes |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Tue May 14, 2013 8:03 am |
|
|
I checked the ground connections - they are OK! The led is blinking correctly!
Onther ideas? |
|
|
|