PDA

View Full Version : explanation on I2C command (PBP)



F1CHF
- 15th January 2006, 20:23
hello
In the ONLINE help I found the I2C command explanation, see below

I2CWRITE DataPin,ClockPin,Control,{Address,}[Value{,Value...}]{,Label}

I2CWRITE sends Control and optional Address out the I2C ClockPin and DataPin followed by Value.

Questions :
1/ what is the meaning of CONTROL ? for me an I2C device as
a one byte adress (let's say 00 to FF) control is optional in this case ?
2/ what the meaning of LABEL, I mean goto this label on which state or result
if command well done or in case of error (I suppose error case )
I didn't find any explanation on thoses terme.
thanks in advance
F1CHF Francois

Melanie
- 16th January 2006, 00:49
control is the device Address which you will determine by reading the DATASHEET for that device...

Example 1... for a DS1307 RTC chip, this Address is $D0.
Example 2... for a 24LC64 EEPROM, this address is in the range $A0-$AE.
Example 3... for an MCP23008 I/O Port Expander, the Address is $40-$4E.

It means you can have multiple devices co-existing on the same bus, as each will have their own unique device address, and will only respond to their own control byte.

Label is as you've already determined, the Label which the program will jump to if there is an error... in this case the I2C slave device fails to respond with an acknowledge. (it is actually in the manual). You can make use of this feature to easily detect if an optional device has been installed.

F1CHF
- 16th January 2006, 08:57
well well Thanks Melanie for your nice and quick answer (as usual !)
may I come back on the control and adress parameters
I understand :
CONTROL is the physical adress of the I2C slave as you said $A0 to $AE for the 24LC64
ADRESS is an optional parameter (in this case a memory location in this eeprom) this parameter is a BYTE so the maximal value is $FF (dec 256)
and the 24LC64 need a 12 bits adress regarding the size.

It is not the case for a SP5055 or PCF8574 which have only ADRESS and
two bytes of data .... in this case parameter adress is ignored ?

I2Cwrite sda,scl, @I2C,[data1, data2], error routine label

Am I right ?, or still "swiming in the marmelade ?"

last sentence is a French translation .. hi ! like me ...
so , sorry for my possible bad translation or writing.

regards,
Francois

Melanie
- 16th January 2006, 09:17
You're pretty much there... except...

24LC32 has a BYTE as the Control Address and a WORD as the Memory Address.

Without looking at the Datasheets for those two devices you quoted I can't say, but EEPROMs for example need the Memory Address, other devices (like the RTC or I/O Expander) don't so you omit it, however in many cases it is replaced by an internal REGISTER Address for the I2C Slave Device. Again refer to your Datasheet for your particular I2C Slave device.

Example for DS1307 RTC...

I2CAddress=$D0 ' Device Address
I2CRegister=0 ' Get Seconds Register
I2CRead SDA,SCL,I2CAddress,I2CRegister,[DataA],I2CDataError

If swimming in marmalade - bring some toast...

n0yox
- 12th May 2014, 05:30
Melanie

I am having a time with the RDA1846, the data sheets says the 7 bit control address is 1110001 plus a read/write bit does I2CWRITE add this read/write bit in the proper place or do I need add it to the control address? It also says it should be sent MSB first is this how I2CWRITE handles this control byte? I am very confused !

ADDRESS VAR BYTE
DATAH VAR BYTE
DATAL VAR BYTE
I2CWRITE DATAIO,CLOCK,%1110001,ADDRESS,[DATAH,DATAL]

Thanks You!
https://dallasmakerspace.org/w/images/3/3f/RDA1846_Programming_manual.pdf "Page 5"