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

I2C problem help me..

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



Joined: 24 Nov 2004
Posts: 3
Location: Korea, Seoul

View user's profile Send private message MSN Messenger

I2C problem help me..
PostPosted: Thu Dec 02, 2004 9:48 pm     Reply with quote

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..
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Dec 02, 2004 10:19 pm     Reply with quote

Do you have pull-up resistors on the I2C lines?
Post your code for both master and slave.
Richard



Joined: 24 Nov 2004
Posts: 3
Location: Korea, Seoul

View user's profile Send private message MSN Messenger

hw wa ok!!
PostPosted: Fri Dec 03, 2004 1:00 am     Reply with quote

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..
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 03, 2004 6:45 am     Reply with quote

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?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Dec 03, 2004 8:14 am     Reply with 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.

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.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 03, 2004 8:22 am     Reply with quote

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 Surprised If you keep those isrs short you don't need them!
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