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

General I2C questions PIC16F886

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



Joined: 07 Apr 2010
Posts: 11

View user's profile Send private message

General I2C questions PIC16F886
PostPosted: Wed Apr 14, 2010 12:23 pm     Reply with quote

I got 2 PIC16F886 communicating with each other. However, if I make the slave address odd, it doesn't work.

In the slave file I have
Code:

#use i2c(slave, slow, force_hw, sda=PIN_C4, scl=PIN_C3, address=0x22);

In the master
Code:

#use i2c(master, slow, sda=PIN_C4, scl=PIN_C3)
#define SLAVE_ADDRESS     0x22


This works fine, as done any even numbered address for the slave. As soon as I make the slave address odd, communication stops. Slave addresses 0x33, 0x31, 0x27 all fail to communicate. however 0x30, 0x24, 0x28 all succeed. I also tried to change the address of the slave device in the init function with i2c_slaveaddr(0x33) and it still failed to communicate. I need to be able to use 0x33.

Any ideas why I can't use odd numbers?
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 12:29 pm     Reply with quote

The LSb is reserved as a read/write flag. I suspect this is the cause of your trouble.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 12:40 pm     Reply with quote

Quote:
I need to be able to use 0x33.

Explain this.
johnbravado



Joined: 07 Apr 2010
Posts: 11

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 12:53 pm     Reply with quote

I am working in conjunction with another company. They have a product that wants to interact with ours through i2c communication. They already have many products out there in which their unit, DB, connect to other units, MB. The DB is the master, and it sends out i2c commands to the MB slave address 0x33. As such, we need to work with what they have. We cannot ask the company to use a different address, changing their code and many other peoples code, merely because the CCS compiler cannot handle odd number i2c slave address.

BTW i tested it and if you do the following from the master and change the slave address to 0x32, the slave sends a response. this makes no sense as to why the CCS compiler would eliminate the ability to use odd numbered address when all they had to do was put us in charge of the shifting and read/write bit at the end.
Code:

i2c_start();
i2c_write(0x33);
response = i2c_read(0);
i2c_stop;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 1:12 pm     Reply with quote

Read this post. It explains the difference between the CCS-style slave
address format and the Philips format. Your slave address of 0x33 is
almost certainly in Philips format.
http://www.ccsinfo.com/forum/viewtopic.php?t=38142&start=5&highlight=shifted
johnbravado



Joined: 07 Apr 2010
Posts: 11

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 1:48 pm     Reply with quote

Thanks. I am thinking I am going to have to wait until I get their test box to fully explore this. Just for clarification of how this is working though.

If they are sending to slave address 0x33, I am going to have to address my unit as 0x66.

Just for further clarification. So when I am sending requests I got to think of it as a total byte not seven when it comes to the address. So lets say I was working with another company and they had addressed their units with slave address 0x2F. In order to write to them I would consider what I write for the address as the whole byte with the read/write appended, ie 0x5E for write and 0x5F for read? i2c_write(0x5E) or i2c_write(0x5F).
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 14, 2010 2:00 pm     Reply with quote

For a Philips style slave address of 0x2F, the CCS-style equivalents are:
The i2c write address is 0x5E. The read address is 0x5F.

Look at this example. It has i2c Master and Slave code.
The slave address is 0x12. That address is entered into the #use i2c()
statement for the Slave. The Master then has two constants defined.
The write address is 0x12 and the read address is 0x13.
The two example programs in this post should show it clearly:
http://www.ccsinfo.com/forum/viewtopic.php?t=39242&start=6
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