Calibre UK ICA93LV user manual Getbytes

Page 20

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.

Revision 1.7

Page 19 of 27

09/12/1999

 

Image 20
Contents Contents ICA93LVIntroduction Packing ListWait State Generator Configuring the AdapterSetting the Adapter Base Address Installing the Adapter Bus Termination and ProtectionConnecting the Adapter to your System Connector Pinout Normal/Long Distance ModeVariable Voltage Bus Power Supply Bus Capacitance Limitations/Cable ChoiceGetting Started Resetting the Adapter Introduction to the UtilitiesLibrary/Programs TurboBASIC Library/Programs2. I2C Status Checking Routine Using the UtilitiesRoutines 1. I2C Setup/Initialisation Routine 3. I2C Address and Start Sending Routine 4. I2C Read Data Byte from Slave Routine Write Data Byte to Slave Routine Send an I2C Stop RoutineTurboBASIC Routines 1. I2C Setup/Initialisation Routines 7. I2C Restart and Address Sending Routine2. I2C Status Checking Routine 3. I2C Address and Start Sending Routine Write Data Byte to Slave Routine 7. I2C Restart and Address Sending Routine Setup Visual Basic 3.0 functionSendaddress Restart SendaddressSendstop Getstatus SendbytesGetbytes Slavelastbyte Further Information BUS Error Real-Time Bus MonitorAppendix a I2C Communications Adapter Status Codes Bit 7 MSB The PIN BitBit 6 Not Used Bit 5 The STS BitAppendix B I2C Communications Adapter Control Codes Question Do you have software to talk to my........? DOS Software QuestionsHkeylocalmachine System