Welcome, Guest
Username: Password: Remember me
Messages posted to this category need to be reviewed by the moderator before it gets posted.
  • Page:
  • 1

TOPIC: I2c information

I2c information 5 years 6 months ago #747

  • Toymanf
  • Toymanf's Avatar
  • OFFLINE
  • Posts: 3
  • Karma: 0
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
The administrator has disabled public write access.

Re: I2c information 5 years 6 months ago #748

  • Toymanf
  • Toymanf's Avatar
  • OFFLINE
  • Posts: 3
  • Karma: 0
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
The administrator has disabled public write access.

Re: I2c information 5 years 6 months ago #750

  • csearcy
  • csearcy's Avatar
  • OFFLINE
  • Posts: 459
  • Thank you received: 77
  • Karma: 23
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<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.
a=a+1
PRINT("Got: ",b,#13)
ENDIF
LOOP
CCHN(IIC,1)
END
The administrator has disabled public write access.

Re: I2c information 5 years 6 months ago #753

  • Toymanf
  • Toymanf's Avatar
  • OFFLINE
  • Posts: 3
  • Karma: 0
Thank you Chuck. Looking forward to any additional info you may find.
Frank
The administrator has disabled public write access.

Re: I2c information 5 years 6 months ago #754

  • csearcy
  • csearcy's Avatar
  • OFFLINE
  • Posts: 459
  • Thank you received: 77
  • Karma: 23
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.
The administrator has disabled public write access.
  • Page:
  • 1
Moderators: hsummer, csearcy
Time to create page: 0.286 seconds