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 support@ccsinfo.com

TIP: I2C standard 7-bit addresses versus CCS 8-bit addresses

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



Joined: 17 Jun 2019
Posts: 537
Location: Des Moines, Iowa, USA

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

TIP: I2C standard 7-bit addresses versus CCS 8-bit addresses
PostPosted: Wed Dec 23, 2020 11:40 am     Reply with quote

I am just posting this here in case others stumble upon this when first learning I2C.

The I2C addressing standard is a 7-bit address. Datasheets will often show it like this:

Code:
1000 000
1000 001
1000 010


Or just...

Code:
1000000
1000001
1000010
1000101


On the wire, that address is the sent as 7-bits (address) followed by 1-bit (direction- read or write).

Code:
aaaaaaad -- 7-bit address/direction bit
--------
10000101


Thus, a standard 7-bit address of "1000101" goes out on the wire as:

Code:
aaaaaaad - 7-bit address/direction bit
--------
10001010 - write to 1000101
10001011 - read from 1000101


If I2C things aren't working, check to see how many bits the datasheet is providing. If it is 7-bits, you need to shift them to the left one bit before passing them into the CCS I2C routines.

For example, a part I am adding support for shows 7-bit addresses. I cannot use that address with the I2C functions since they expect an 8-bit address. You can manually shift them over or use a simple macro like this:

Code:

#define I2C7BITADDRESS(addr) (addr<<1)

i2c_slaveaddr( I2C7BITADDRESS(MYDEV7BITADDRESS) );


This allows you to use the 7-bit I2C addresses defined by the datasheet with the CCS code that expects an 8-bit address.

If you find this note in the future, and it helps solve an issue, please leave a reply ;-)
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 23, 2020 12:14 pm     Reply with quote

Ok, I admit, I'm getting old(67) and cranky... but...

I've never understood the logic ( no pun intended) of the 7 bit address for I2C and I remember when Philips brought it out....

You either READ or WRITE to a device which dictates that 8th bit be used.....

Most computers use 8 bits , a byte, as a 'building block', either as a port size or memory width or UART data qty.... it's kind of a 'universally' understood concept.....
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Dec 23, 2020 12:29 pm     Reply with quote

It's wrong really to say 'CCS' in the heading for this, is is the PIC that
does this. In fact though something like 90% of chips also do this which
is why most peripherals now give the 8 bit address format, not the 7 bit
format. The important thing is to distinguish the 'I2C address', from the
'address byte'. The 'address byte' is the 7bit 'I2C address', followed by
the direction flag. The PIC (and CCS), always works with this byte.
Most data sheets now tend to give both the I2C address, and the
corresponding address byte.
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