Understanding i2c addressing syntax

Afternoon (again) ladies and gentlefolks,

Hopefully a quick question with regards to the syntax of the hi2csetup, hi2cout and hi2cin commands, specifically addressing.

My bus is going to have multiple slave devices for various different things. It seems that you have to set a slave address in hi2csetup, and then either run with it or specify a new address in hi2cout/in. Is this assumption correct?

Also, to save my sanity, is there a way to bypass this and to send data on the bus exactly as written on screen, so for example hi2cout $0F $FF $FF, where in this example $0F is the device address? Would make the programming easier in my mind at least :)
 

hippy

Technical Support
Staff member
It seems that you have to set a slave address in hi2csetup, and then either run with it or specify a new address in hi2cout/in. Is this assumption correct?
That is correct.

Also, to save my sanity, is there a way to bypass this and to send data on the bus exactly as written on screen, so for example hi2cout $0F $FF $FF, where in this example $0F is the device address? Would make the programming easier in my mind at least :)
That cannot be done directly, but if you don't like how it is you might be able to create a #MACRO which allows you write what you want and have the macro generate what the PICAXE needs it to be.

It might be easier to just get used to the PICAXE syntax used.
 

hippy

Technical Support
Staff member
So the syntax would be hi2cout [$0F], $FF, $FF........
Actually, where {...} are optionals -

HI2Cout { [ <deviceId> ] , } { <location> , } ( <data> { , <data> ... } )

So for example -

HI2Cout [$A0], ( $AA, $BB )
HI2Cout [$A0], $0F, ( $AA, $BB )

Is it possible to use the contents of a variable to replace the newaddress and location?
The easiest way to answer those sort of questions is to try it; write a line of code and Syntax Check. If it passes then it's allowed.

In this case the answer is yes, that's allowed.
 

Aries

New Member
Just a thought ...
If you are interfacing with different devices, some of which use i2cword and some i2cbyte, I suspect you have to re-do the hi2csetup as well, because changing address does not change the byte/word addressing. I have taken to doing "hi2csetup off", then checking that there is nothing untoward with the scl and sda, and then opening the new i2c (again taken from the heating controller).

Code:
.......
    gosub CloseI2C
    hi2csetup i2cmaster,I2cActuatorSlave,i2cslow,i2cbyte
.......
CloseI2C:
    hi2csetup off
    input I2C_SDA
    if I2C_SDApin = 0 then                ' I2C stuck
         for b0 = 0 to 15
            if I2C_SDApin = 0 then
                low I2C_SCL                            ' pull low
                pause 10
                input I2C_SCL                        ' allow to go high
            endif
        next b0
    endif
    input I2C_SCL
    return
 
Top