I2C Handshaking Using PICAXE Chips

DL8OV

New Member
I want to use a PICAXE chip as the interface between a front panel and a sound recorder chip, the ISD5116, the only problem is that the chip uses I2C which is something I'm not familiar with. Here is an example, how to write to a register:

1. Host executes I 2C START
2. Send Slave Address with R/W bit = “0” (Write)
3. Slave responds back with an ACK.
4. Wait for SCL to go HIGH
5. Host sends a byte to Slave - (Command Byte)
6. Slave responds with an ACK
7. Wait for SCL to go HIGH
8. Host sends a byte to Slave - (High Address Byte)
9. Slave responds with an ACK
10. Wait for SCL to go HIGH
11. Host sends a byte to Slave - (Low Address Byte)
12. Slave responds with an ACK
13. Wait for SCL to go HIGH
14. Host executes I 2C STOP

What concerns me are steps 1,4,7,10 & 13, is this handshaking built in to the PICAXE firmware when using the I2C routines or do I need extra lines in my code to test the status of the I2C lines before sending the next byte?

Regards

Peter DL8OV
 

Technical

Technical Support
Staff member
1. Host executes I 2C START
2. Send Slave Address with R/W bit = “0” (Write)
3. Slave responds back with an ACK.
4. Wait for SCL to go HIGH
5. Host sends a byte to Slave - (Command Byte)
6. Slave responds with an ACK
7. Wait for SCL to go HIGH
8. Host sends a byte to Slave - (High Address Byte)
9. Slave responds with an ACK
10. Wait for SCL to go HIGH
11. Host sends a byte to Slave - (Low Address Byte)
12. Slave responds with an ACK
13. Wait for SCL to go HIGH
14. Host executes I 2C STOP
=
hi2cout command_byte,(high_byte, low_byte)

Don't forget to use hi2csetup once at the top of the program as well.
 

DL8OV

New Member
As the procedure given was to output three bytes with handshaking between each byte why is the command

hi2cout command_byte,(high_byte, low_byte)

rather than

hi2cout command_byte,high_byte, low_byte?

In other words, what do the brackets do?

Regards

Peter DL8OV
 

Technical

Technical Support
Staff member
Many i2c devices, such as eeproms and your device, have a single address but can then have multiple data byes, e.g. between 1 and 16 bytes of data.
So the brackets visually distinguish between the address and the data, it's purely for ease of reading by the human programmer.
It also has importance when you use a word address eeprom (i2cword in hi2csetup), as the address is actually two bytes on the i2c bus, but can be written as as single word number before the brackets.

However in your case, if you prefer, you can just use

hi2out (command_byte, high_byte, low_byte)

which is actually exactly the same as this (as it is byte address part)

hi2out command_byte, (high_byte, low_byte)
 

westaust55

Moderator
Some i2c devices, such as larger EEPROM chips also require a word value to define the starting location for reading or writing. The the format is:
HI2COUT Location_word, (outbyte1, outbyte,2 {,more_bytes_as_required} )

Further some i2c devices when reading require a command or location immediately following the slave address byte in which case the format is:
HI2CIN command_byte, (inbyte1, inbyte2 {,more_bytes_as_required} )
If there are no brackets, how does a reader or the PICAXE programming editor know for sure whether the command_byte is in fact an outgoing or incoming byte?

Hence the use of brackets also provides consistency across the BASIC i2c commands.
 
Top