Calibre UK ICA93LV user manual 4. I2C Read Data Byte from Slave Routine

Page 9
int base, slv, setnack; base = 0x310;
slv = 0xa0; setnack = 0;

{

/* Adapter’s bas address = 0x310 (hex) */ /* I2C Address of slave, this is a typical */ /* write for an I2C static RAM or EEPROM */ /* Enable Acknowledge (see parameter */ /* descriptions) */

sendaddress(base, slv, setnack); printf(“Start and I2C Slave Address sent\n”);

}

/* This will send a start and the I2C Slave Address of the device */ /* to be communicated with. */

5.1.4.I2C Read Data Byte from Slave Routine

Name:

readbyte(base, setnack)

Usage:

data = readbyte(base, setnack);

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.

Note: First byte read after read-address is always that address and should be discarded. This byte should be ignored when working out when to acknowledge/not acknowledge.

Parameters are:

 

int base

The base address of the I2C Communications Adapter set by links on circuit

 

board.

int setnack

This controls whether the I2C Communications Adapter transmits an

 

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 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 set = 0. (in case of reading 1 byte only,

 

acknowledge will have been disabled by sendaddress and so should now be

 

enabled again after reading the data, hence setnack = 0 for reading a single byte

 

of data.)

Value Returned:

 

int <data>

The function reads the byte of data and returns an integer equal to the value

 

read.

I2C status on exit from routine:

 

The status of the I2C Communications Adapter will be either 0x00 - bus busy and

 

unread data in the data register or 0x80 - bus busy and no unread data in the

 

data register depending on whether any more bytes of data have been

 

transmitted by the slave device which is being read. (See Appendix A for details

 

of the status Codes).

Example Usage:

(see also sample programs)

#include <stdio.h>

 

#include <dos.h>

/* Optional, but recommended if your compiler */

 

/* supports DOS I/O functions */

#include <i2c.h>

/* This contains the I2C functions */

main

 

{

 

int base, setnack, data;

 

base = 0x310;

/* Adapter’s base address = 0x310 (hex) */

setnack = 0;

/* Enable acknowledge - only one byte it to */

 

/* be read (see parameter descriptions) */

data = readbyte(base, setnack);

printf(“Data read was %x\n”, data);

}

 

Revision 1.7

Page 8 of 27

09/12/1999

 

Image 9
Contents ICA93LV ContentsPacking List IntroductionConfiguring the Adapter Setting the Adapter Base AddressWait State Generator Bus Termination and Protection Installing the AdapterNormal/Long Distance Mode Connecting the Adapter to your System Connector PinoutVariable Voltage Bus Power Supply Bus Capacitance Limitations/Cable ChoiceIntroduction to the Utilities Getting Started Resetting the AdapterLibrary/Programs TurboBASIC Library/ProgramsUsing the Utilities Routines 1. I2C Setup/Initialisation Routine2. I2C Status Checking Routine 3. I2C Address and Start Sending Routine 4. I2C Read Data Byte from Slave Routine Send an I2C Stop Routine Write Data Byte to Slave Routine7. I2C Restart and Address Sending Routine TurboBASIC Routines 1. I2C Setup/Initialisation Routines2. I2C Status Checking Routine 3. I2C Address and Start Sending Routine Write Data Byte to Slave Routine 7. I2C Restart and Address Sending Routine Visual Basic 3.0 function SetupSendaddress Sendaddress SendstopRestart Sendbytes GetstatusGetbytes Slavelastbyte Further Information Real-Time Bus Monitor BUS ErrorBit 7 MSB The PIN Bit Appendix a I2C Communications Adapter Status CodesBit 6 Not Used Bit 5 The STS BitAppendix B I2C Communications Adapter Control Codes DOS Software Questions Question Do you have software to talk to my........?Hkeylocalmachine System