Calibre UK PICA93LV user manual Calibre

Page 14
Parameters are:
Value Returned:
I2C status on exit:

CALIBRE

￿

￿

4.2.5.Write Data Byte to Slave Routine

Function definition:

int writebyte(int i2cdata)

Usage:

i2cstatus = writebyte(i2cdata)

Function:

This is the procedure to write a byte of data to a slave device whose slave

 

address has already been sent by sendaddress.

int 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 0x8000 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.C, this value may be altered to suit your system.

0x00 bus busy and data transmitted and acknowledged successfully.

0x08 bus busy and data transmitted successfully but not acknowledged . 0x80 bus busy and data not transmitted

(See Appendix A for details of status codes).

Example Usage: (see also sample programs)

/* This will write a byte of data to a slave previously addressed by sendaddress. */ main()

{

int i2cdata, i2cstatus;

i2cdata = 0x69; /* Data byte which is to be transmitted */ i2cstatus = writebyte (i2cdata) ;

if (i2cstatus & 0x8000) == 0x8000

{

printf("Data has not been transmitted status is %x\n", i2cstatus);

}

else

{

printf("Data has been transmitted\n");

}

}

Issue 1.3

Page 11

22/07/99

Image 14
Contents Calibre Calibre CopyrightContents General Introduction Configuring the AdapterIntroduction Packing ListInstalling the Adapter Typical PC ConnectionPower Supply Connecting the Adapter to Your SystemConnector Pinout Bus Capacitance Limitations\C\CLIB\CPICA.LIB Software Utilities\C\CLIB\SPICA.LIB \C\CLIB\MPICA.LIB\B\SOURCE\PROMREAD.BAS DOS Qbasic Library/Programs\B\SOURCE\I2CINC.BAS \B\SOURCE\PROMWRIT.BASWindows LIB/DLL Functions Int ownaddress Using the UtilitiesRoutines Int sclkInt setnack Int i2cstatusInt slaveaddress Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave Sclk% Qbasic RoutinesOwnaddress% 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 7 MSB The Pending Interrupt Not PIN Bit Bit 4 The Bus Error BER BitAppendix a Parallel I2C Communications Adapter Status Codes Bit 6 Not UsedAppendix B Parallel I2C Communications Adapter Control Codes Question Do you have software to talk to my........? Question Get corrupted transfers why is this?Most Commonly Asked I2C Questions QuestionCode. Why? Please Email Your Query to