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

Problem with USART communication between 2 x 18F66J60
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Problem with USART communication between 2 x 18F66J60
PostPosted: Fri May 03, 2013 9:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 03, 2013 9:47 am     Reply with quote

Quote:
putc(5,first);

This line sends a binary 5 not the ascii number 5.

try this:
Code:
putc('5',first);

_________________
Google and Forum Search are some of your best tools!!!!
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri May 03, 2013 10:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 03, 2013 10:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 03, 2013 11:03 am     Reply with quote

I`ve missed that! I`ll add it and see what`s gonna happen!
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri May 03, 2013 2:13 pm     Reply with quote

Now everything works fine! I can`t explain it....
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Fri May 03, 2013 2:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 09, 2013 10:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 09, 2013 11:13 am     Reply with quote

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: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu May 09, 2013 1:04 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 13, 2013 11:08 am     Reply with quote

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: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 13, 2013 11:14 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 13, 2013 11:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 13, 2013 2:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue May 14, 2013 8:03 am     Reply with quote

I checked the ground connections - they are OK! The led is blinking correctly!
Onther ideas?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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