Calibre UK PICA93LV DOS Qbasic Library/Programs, B\SOURCE\I2CINC.BAS, B\Source\Promread.Bas

Page 8

CALIBRE

￿

￿

The I2CINC.C file contains all the functions required to build an I2C transfer. This will require compiling (note the include file) to produce an object file. Once the object files have been created link them together with the library file to create your applications executable file.

The functions contained in I2CINC.C are as detailed below:-

Subroutine Name

Brief Functional Description

setup

Sets user defined initial conditions.

getstatus

Reads status register.

sendaddress

Sends slave address, data transmission mode and start signal.

sendstop

Sends stop signal.

writebyte

Writes a byte of data to a previously specified address.

readbyte

Reads a byte of data from a previously specified address.

restart

Sends Restart and slave address of device which is to be communicated

 

with, without sending a Stop.

Two sample programs are also supplied, these examples show how the functions provided in I2CINC.C are put together to provide a complete I2C transfer. The sample programs are:-

PROMREAD.C

Reads a number of bytes from an I2C serial EEPROM.

PROMWRIT.C

Writes a number of bytes to an I2C serial EEPROM.

These programs were compiled using the Zortech C compiler the make files used are supplied. If you are using the Zortech C compiler copy the desired make file to MAKEFILE then type MAKE<CR>. Editing the make files will reveal that the file I2CINC.C is compiled and linked with the application.

The makefiles are:-

 

READ.MAK

The make file for PROMREAD.C

WRITE.MAK

The make file for PROMWRIT.C

If you are not using the Zortech C compiler you will have to create a similar make file - see your compiler documentation for further information.

3.3.DOS QBASIC Library/Programs

3.3.1.Files on disc

\B\SOURCE\I2CINC.BAS

The I2C transfer functions

\B\SOURCE\PROMREAD.BAS

Sample EEPROM reading function

\B\SOURCE\PROMWRIT.BAS

Sample EEPROM writing function

The I2C functions contained in I2CINC.BAS are detailed below:-

Subroutine Name

Brief Functional Description

setup

Sets user defined initial conditions.

getstatus%

Reads status register.

sendaddress%

Sends slave address, data transmission mode and start signal.

sendstop%

Sends stop signal.

writebyte%

Writes a byte of data to a previously specified address.

readbyte%

Reads a byte of data from a previously specified address.

restart%

Sends restart and slave address of device which is to be communicated with,

 

without sending a Stop.

Two sample programs are also supplied, these examples show how the functions provided in I2CINC.BAS are put together to provide a complete I2C transfer. The sample programs are:-

PROMREAD.BAS

Reads a number of bytes from an I2C serial EEPROM.

PROMWRIT.BAS

Writes a number of bytes to an I2C serial EEPROM.

Issue 1.3

Page 5

22/07/99

Image 8
Contents Calibre Calibre CopyrightContents Configuring the Adapter IntroductionGeneral Introduction Packing ListInstalling the Adapter Typical PC ConnectionConnecting the Adapter to Your System Connector PinoutPower Supply Bus Capacitance LimitationsSoftware Utilities \C\CLIB\SPICA.LIB\C\CLIB\CPICA.LIB \C\CLIB\MPICA.LIBDOS Qbasic Library/Programs \B\SOURCE\I2CINC.BAS\B\SOURCE\PROMREAD.BAS \B\SOURCE\PROMWRIT.BASWindows LIB/DLL Functions Using the Utilities RoutinesInt ownaddress Int sclkInt setnack Int i2cstatusInt slaveaddress Calibre Int i2cdata Calibre Int i2cstatus Number if the adapter is to read from the slave Qbasic Routines Ownaddress%Sclk% I2cstatus%Slaveaddress% Setnack% I2cdata%See Appendix a for details status codes I2cstatus% Is to read from the slave Int statuswait Libraries for Programming in Microsoft Windows EnvironmentsInt baseaddress Int ErrCode Int wrDataSendaddress Address to be accessed via the I2C, e.g. A1H Int bsent Int sendbytesint far *transferarrayInt far *transferarray Int getbytesint far *transferarray Int nobytesreadSlave using the adapter Further Information Bit 4 The Bus Error BER Bit Appendix a Parallel I2C Communications Adapter Status CodesBit 7 MSB The Pending Interrupt Not PIN Bit Bit 6 Not UsedAppendix B Parallel I2C Communications Adapter Control Codes Question Get corrupted transfers why is this? Most Commonly Asked I2C QuestionsQuestion Do you have software to talk to my........? QuestionCode. Why? Please Email Your Query to