Calibre UK PICA93LV Benutzerhandbuch

Seite von 35
CALIBRE
Issue 1.3
 
Page 17
22/07/99
(See Appendix A for details status codes).
Example Usage:
(see also sample programs)
' This will read a byte of data from a slave previously addressed by and with acknowledge already '
disabled by sendaddress. After reading the data, acknowledge will be re-enabled.
Sub Main
setnack% = 0
' Enable Acknowledge - only one byte is to be read
' (see parameter descriptions)
i2cdata% = readbyte(setnack%)
if i2cdata and &H8000 = &H8000 then
print "Data read fault i2c status " + Hex$(i2cdata%)
else
print "Data read was " + Hex$(i2cdata%)
end if
Exit Sub
4.3.5.
Write Data Byte to Slave Routine
Function definition:
writebyte%(i2cdata as integer)
Usage:
i2cstatus% = writebyte(i2cdata%)
Function:
procedure to write a byte of data to a slave device whose slave address has
already been sent by sendaddress.
Parameters are:
i2cdata%
The byte of data which is to be written to the slave device.
Value Returned:
The value returned depends on whether the data was written successfully.
If the data was written then the status is returned.
If the data cannot be written then the last status read IORed with &H8000 will
be returned.
The function will read the status a number of times before returning an error
condition - this number is defined by the MAXNUMBEROFGOES constant
defined in I2CINC.BAS, this value may be altered to suit your system.
I2C status on exit:
&H00 bus busy and data transmitted and acknowledged successfully.
&H08 bus busy and data transmitted successfully but not acknowledged .
&H80 bus busy and data not transmitted
(See Appendix A for details of Status codes).