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