View previous topic :: View next topic |
Author |
Message |
Richard
Joined: 24 Nov 2004 Posts: 3 Location: Korea, Seoul
|
I2C problem help me.. |
Posted: Thu Dec 02, 2004 9:48 pm |
|
|
I tried to connect two pics by using I2C
of course, One pic is as master and others is as slave..
but... when i transmitted data from slave to master..
the data in master was just 0xff..
how to can i receive correct data..?
what am i wrong.. |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Thu Dec 02, 2004 10:19 pm |
|
|
Do you have pull-up resistors on the I2C lines?
Post your code for both master and slave. |
|
![](templates/subSilver/images/spacer.gif) |
Richard
Joined: 24 Nov 2004 Posts: 3 Location: Korea, Seoul
|
hw wa ok!! |
Posted: Fri Dec 03, 2004 1:00 am |
|
|
yes..i connected pull-up reg.. 1k ohm..
data tranmited from master to slave was ok but..just in slave data was shifted and last bit was set..;;
that is also my another problem.. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Dec 03, 2004 6:45 am |
|
|
Quote: | when i transmitted data from slave to master |
Well this statement bothers me. Why you ask, because slaves don't really "transmit" the data but rather the master "clocks" the data from the slave.
Quote: | data tranmited from master to slave was ok |
So are you saying that the slave received the data perfectly meaning no problems or that:
Quote: | slave data was shifted and last bit was set |
Meaning that the data from the master to slave was shifted?
What exactly are you trying to accomplish with the 2 pics? |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Dec 03, 2004 8:14 am |
|
|
Please correct me if I am wrong,.. but from the I2C definition the PIC that clocks the data is the MASTER.(from the definition) The master can send and
recieve data from the slave. So if you have 2 pics (#1 and #2) with #1 as the master. You can have #1 send data and read data from #2.
The thing to keep in mind is that the master is writes and reads with a simple statement. eg:i2c_write(). While the slave uses an interupt and a irq handling routine to handle the data.
Now maybe the examples will make sense.
Also keep you slave address even. Don't change it to an odd address. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Dec 03, 2004 8:22 am |
|
|
Quote: | Please correct me if I am wrong,.. but from the I2C definition the PIC that clocks the data is the MASTER.(from the definition) The master can send and
recieve data from the slave. So if you have 2 pics (#1 and #2) with #1 as the master. You can have #1 send data and read data from #2.
|
Yep.
Quote: | Also keep you slave address even. Don't change it to an odd address. |
Correct statement but might be a little confusing to some.
Addresses are always even. Odd addresses are for addressing the slave in read mode. So say we want to send a command to query some data from a slave. We would:
1. Send a start
2. Send an address (even)
3. Send command
4. Send another start (so we can keep the bus and tell the pic that the next byte is an address)
5. Send address + 1 (this is where the odd address is)
6. Read data acking each byte except the last (i2c_read(1))
7. Stop
Do this make sense now?
PS: On the newer pics the master is implemented in firmware so you could do a isr transmit (I don't though).
PSS: Why the heck does everybody keep putting those delays between master writes If you keep those isrs short you don't need them! |
|
![](templates/subSilver/images/spacer.gif) |
|