CALIBRE
Sub Main |
|
slaveaddress% = &HA0 | ' IC Address of slave, this is a typical write |
| ' address for an I2C static RAM or EEPROM |
setnack% = 0 | ' Enable Acknowledge (see parameter descriptions) |
i2cstatus% = sendaddress (slaveaddress%, setnack%) Select Case i2cstatus%
case &H00
print "Start and I2C Slave Address sent and acknowledged" case &H08
print "Start and I2C Slave Address sent and not acknowledged" case else
print "Start not sent status is " + Hex$( i2cstatus%)
End Select End sub
4.3.4.I2C Read Data Byte from Slave Routine
Function definition: | readbyte%(setnack as integer) |
Usage: | i2cdata% = readbyte%(setnack%) |
Function: | function to read a byte of data from a slave device whose slave address has |
| already been sent by sendaddress. Can be used to disable acknowledge after |
| reading data if it is the last but one byte to be read. |
Parameters are: | setnack% |
| This controls whether the Parallel I2C Communications Adapter transmits |
| and Acknowledge down the I2C Bus on reception of a byte. The last byte |
| received during a transfer must not be acknowledged, in all other cases |
| acknowledge must be enabled. If setnack% = 0 then acknowledge is enabled, |
| if setnack% = 1 then acknowledge is disabled. Therefore, if the LAST BUT |
| ONE byte is to be read, setnack% should be set to =1; in all other cases it |
| must be clear = 0. (In the case of reading 1 byte only, acknowledge will have |
| been disabled by sendaddress and so should now be enabled again after |
| reading the data.) |
Value Returned: | i2cdata% |
| The value returned depends on whether the data was read successfully. |
| If the data was read then the value is returned. |
| If the data cannot be read (because there is none in the register) 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.C, this value may be altered to suit your system. |
I2C status on exit : | 0x00 bus busy and unread data in data register. |
| 0x80 bus busy and no unread data in data register |
| The value will depend on whether any more bytes of data have been |
| transmitted by the slave device which is being read. |
Issue 1.3 | Page 16 |
22/07/99