Calibre UK PICA93LV user manual See Appendix a for details status codes

Page 20

CALIBRE

￿

￿

 

(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:

Value Returned:

I2C status on exit:

i2cdata%

The byte of data which is to be written to the slave device.

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.

&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).

Issue 1.3

Page 17

22/07/99

Image 20
Contents Calibre Calibre CopyrightContents Configuring the Adapter IntroductionGeneral Introduction Packing ListInstalling the Adapter Typical PC ConnectionConnecting the Adapter to Your System Connector PinoutPower Supply Bus Capacitance LimitationsSoftware Utilities \C\CLIB\SPICA.LIB\C\CLIB\CPICA.LIB \C\CLIB\MPICA.LIBDOS Qbasic Library/Programs \B\SOURCE\I2CINC.BAS\B\SOURCE\PROMREAD.BAS \B\SOURCE\PROMWRIT.BASWindows LIB/DLL Functions Using the Utilities RoutinesInt ownaddress Int sclkInt setnack Int i2cstatusInt slaveaddress Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave Qbasic Routines Ownaddress%Sclk% I2cstatus%Slaveaddress% Setnack% I2cdata%See Appendix a for details status codes I2cstatus% Is to read from the slave Int statuswait Libraries for Programming in Microsoft Windows EnvironmentsInt baseaddress Int ErrCode Int wrDataSendaddress Address to be accessed via the I2C, e.g. A1H Int bsent Int sendbytesint far *transferarrayInt far *transferarray Int getbytesint far *transferarray Int nobytesreadSlave using the adapter Further Information Bit 4 The Bus Error BER Bit Appendix a Parallel I2C Communications Adapter Status CodesBit 7 MSB The Pending Interrupt Not PIN Bit Bit 6 Not UsedAppendix B Parallel I2C Communications Adapter Control Codes Question Get corrupted transfers why is this? Most Commonly Asked I2C QuestionsQuestion Do you have software to talk to my........? QuestionCode. Why? Please Email Your Query to