I2c information
 
Notifications
Clear all

I2c information

5 Posts
1 Users
0 Reactions
12.7 K Views
(@Toymanf)
Posts: 3
New Member Guest
Topic starter
 

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.
Thank you,
Frank

 
Posted : 14/11/2012 9:00 am
(@Toymanf)
Posts: 3
New Member Guest
Topic starter
 

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
Frank

 
Posted : 14/11/2012 2:49 pm
(@csearcy)
Posts: 316
Reputable Member Guest
 

Hi Frank... I'm searching for more documentation. I did find this example code though. More later.
-Chuck

Demo program:

' In this example, the device address is decimal 64 to write,
' and 65 to read.

OCHN(IIC,1,N,60000,1,8,D)
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.

a=0
WHILE a-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.
a=a+1
PRINT("Got: ",b,#13)
ENDIF
LOOP
CCHN(IIC,1)
END

 
Posted : 14/11/2012 6:55 pm
(@Toymanf)
Posts: 3
New Member Guest
Topic starter
 

Thank you Chuck. Looking forward to any additional info you may find.
Frank

 
Posted : 15/11/2012 7:29 am
(@csearcy)
Posts: 316
Reputable Member Guest
 

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:

OCHN(IIC,1,N,baud,1,8,D)
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.

RGETCHR1
Var=GETCHR1
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.

RLEN1
=LEN1
Gets the amount of bytes in the receive buffer.

 
Posted : 15/11/2012 7:44 am
Share: