Revision 1.7 Page 19 of 27
09/12/1999
When all the bytes have been transmitted a stop is issued and the total
number of bytes is returned.
Sendbytes can only be used in master write mode.
getbytes
Function specification Int getbytes (int far *transferarray)
The far pointer must point to a single dimensional array the format of which is detailed below.
The calling function must have initialised elements 0, 1 and 2 prior to calling the function.
Element no Element name Description
0 Slaveaddress Slaveaddress is the address to be accessed via the I2C
Bus, this is in hexadecimal e.g. A0H.
1 Wordaddress Wordaddress is the offset within the slave to which the
first byte of data is to be written, see transmission
format for more detail.
2 Nobytes The number of bytes (n) to be sent. Min value 1.
3 byte 0 First byte read.
byte n Last byte read.
Parameters returned nobytesread, the number of bytes actually read.
Prerequisites Adapter must be configured using setup. Array elements 0, 1 and 2
must be initialised. Elements 3 to n do not need to be initialised since
they are where the read data is returned. Array must be pre-defined to a
size at least large enough to hold all the parameters and data concerned.
Transmission format If the slaveaddress has the least significant but set (1) then this forms a
read address, if the least significant bit is clear (0) then this forms the
write address e.g. A0H is the write address and A1H is the associated
read address.
Getbytes supports two transfer formats these being:
i. start-slavereadaddress-byte(s)-stop
To select transfer format i.) pass the read address as slave address.
The wordaddress is not used in this format and is ignored by getbytes.
ii. start-slavewriteaddress-wordaddress-restart-slavereadaddress-byte(s)-stop
To select transfer format ii.) pass the write address as slaveaddress.
In this format the wordaddress must be valid.
Wordaddress is a pointer to the first byte of data to be read.
Nobytestoread is the number of bytes to be read. The minimum value allowable is 1.
Functional description The function determines the required transmission transfer format,
sends the appropriate sequence of start(s) and slave address(es) and
checks for acknowledges where necessary.
If the slave fails to acknowledge then a stop is sent and nobytesread is
returned equal to 0.
The first data byte read is the slave read address sent(see readbyte
description). This is discarded, it is not returned in the transfer array. The
data bytes are then read and stored in the transfer array. At the
appropriate point acknowledges are ceased – for the last and the last but
one byte to be transferred.
A stop is sent after the last byte has been read. On completion the
number of bytes read is returned.
Should a time-out occur the transfer is terminated by a stop and the
number of bytes successfully read is returned.