Messages posted to this category need to be reviewed by the moderator before it gets posted.
TOPIC: I2c information
I2c information 3 years, 11 months ago #747
Can you please provide links to any example code you have that would help me to understand the v4.15c firmware I2c communication protocol.
I would like to Print to an lcd which I believe I have figured out. But any related documents and examples would be a great help.
Re: I2c information 3 years, 11 months ago #748
I am really looking for any working examples of code which also read and write to the Anilink/I2c port.
I am trying to expand my I/O. Any help would be greatly appreciated
Re: I2c information 3 years, 11 months ago #750
Hi Frank... I'm searching for more documentation. I did find this example code though. More later.
' In this example, the device address is decimal 64 to write,
' and 65 to read.
PRINT1(IIS,#64,#255,IIP) ' Write decimal 64 (address-write),
' then 255 to IIC device
PRINT1(IIS,#65,IIG1,IIP) ' Write decimal 65 (address-read)
' Expect 1 byte from the IIC device
WHILE LEN1==0 WAIT=10 LOOP
RGETCHR1 ' Report that one byte.
PRINT1(IIS,#65,IIG8,IIP) ' Expect 8 bytes from the IIC device.
WHILE a<8 ' ** this loop will keep trying until
' all 8 bytes come in.
b=GETCHR1 ' Get a value from buffer
IF b>-1 ' If the value is -1, then the
' buffer was empty.
ab[a]=b ' Store the value into a byte array
' once we know it is valid.
Re: I2c information 3 years, 11 months ago #753
Thank you Chuck. Looking forward to any additional info you may find.
Re: I2c information 3 years, 11 months ago #754
3.0 – IIC communication
IIC communication involves 5 commands:
OCHN to open the IIC channel
CCHN to close the channel
PRINT1 to send data, address, and request a response from IIC device.
GETCHR1 to read the buffer of values returned from device.
RLEN1 to read how many received bytes are ready.
The OCHN command is the following format:
IIC – the literal syntax IIC to tell what kind of communication this is.
1 - the literal value 1, since this is the location of that port.
N – literal, not relevant to IIC
Baud – the bit rate for communication with the IIC device.
1 – literal, not relevant to IIC
8 – literal, not relevant to IIC
D – literal: always in data mode for IIC communication.
CCHN(IIC,1) - closes the channel.
PRINT1(arg1, arg2, … ,arg_n)
Where arg is:
IIS – Start or restart an IIC command. For IIC devices that require a restart, simple call the IIS command a second time within a print.
IIP – stoP an IIC command.
IIGn – get n bytes from the IIC channel (requires the previous commands to have provided whatever addressing or command is required for the device to start sending. The G argument will provide the right number of clock intervals to ‘pump’ the IIC device to get the data.
Gets the data returned from the IIC device (if available). The data is always in unsigned byte values. So it is advised to assign the data to a 16 or 32-bit register first in order to test for special cases.
For example, the value will be 0-255 for normal data representing all possible values for the byte. If the value from the GETCHR1 command is -1, that indicates the buffer was empty.
Gets the amount of bytes in the receive buffer.
Time to create page: 0.64 seconds