com.dalsemi.system
Class I2CPort

java.lang.Object
  |
  +--com.dalsemi.system.I2CPort

public class I2CPort
extends java.lang.Object

Class allowing access to I2C bus.
This class uses the I2C protocol on one of two resources:


Field Summary
 byte clockDelay
          How long to wait between I2C edge transitions.
 int SCLAddress
          Memory mapped address of the I2C clock line.
 byte SCLMask
          Bit mask for clock line within byte at SCLAddress.
 int SDAAddress
          Memory mapped address of the I2C data line.
 byte SDAMask
          Bit mask for data line within byte at SDAAddress.
 byte slaveAddress
          I2C address of slave.
static byte STRETCH0
          When in memory map mode, use to set the number of memory bus cycles to 2.
static byte STRETCH1
          When in memory map mode, use to set the number of memory bus cycles to 3.
static byte STRETCH10
          When in memory map mode, use to set the number of memory bus cycles to 12.
static byte STRETCH2
          When in memory map mode, use to set the number of memory bus cycles to 4.
static byte STRETCH3
          When in memory map mode, use to set the number of memory bus cycles to 5.
static byte STRETCH7
          When in memory map mode, use to set the number of memory bus cycles to 9.
static byte STRETCH8
          When in memory map mode, use to set the number of memory bus cycles to 10.
static byte STRETCH9
          When in memory map mode, use to set the number of memory bus cycles to 11.
 byte stretchCycles
          Number of stretch memory cycles to use when accessing memory mapped IO.
 
Constructor Summary
I2CPort()
          Use processor port pins for SCL and SDA.
I2CPort(int SCLAddress, byte SCLMask, int SDAAddress, byte SDAMask)
          Use memory mapped IO address for SCL and SDA pins.
 
Method Summary
 int getStretchCycles()
          Gets the number of stretch memory cycles to use when accessing memory mapped IO.
 int read(byte[] barr, int off, int len)
          Reads into the byte array from the current slave address
 void setAddress(byte address)
          Sets the I2C slave address.
 void setClockDelay(byte delay)
          Sets how long to wait between I2C edge transitions.
 void setStretchCycles(byte stretch)
          Sets the number of stretch memory cycles to use when accessing memory mapped IO.
 int write(byte[] barr, int off, int len)
          Writes the byte array to the current slave address
 int writeread(byte[] wbarr, int woff, int wlen, byte[] rbarr, int roff, int rlen)
          Writes and then reads from/into the byte arrays from the current slave address
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRETCH0

public static final byte STRETCH0
When in memory map mode, use to set the number of memory bus cycles to 2.

STRETCH1

public static final byte STRETCH1
When in memory map mode, use to set the number of memory bus cycles to 3.

STRETCH2

public static final byte STRETCH2
When in memory map mode, use to set the number of memory bus cycles to 4.

STRETCH3

public static final byte STRETCH3
When in memory map mode, use to set the number of memory bus cycles to 5.

STRETCH7

public static final byte STRETCH7
When in memory map mode, use to set the number of memory bus cycles to 9.

STRETCH8

public static final byte STRETCH8
When in memory map mode, use to set the number of memory bus cycles to 10.

STRETCH9

public static final byte STRETCH9
When in memory map mode, use to set the number of memory bus cycles to 11.

STRETCH10

public static final byte STRETCH10
When in memory map mode, use to set the number of memory bus cycles to 12.

stretchCycles

public byte stretchCycles
Number of stretch memory cycles to use when accessing memory mapped IO. Valid values are:
STRETCH0
STRETCH1
STRETCH2
STRETCH3
STRETCH7
STRETCH8
STRETCH9
STRETCH10

slaveAddress

public byte slaveAddress
I2C address of slave. Right justified, least significant bit of this byte = least significant bit of I2C slave address.

clockDelay

public byte clockDelay
How long to wait between I2C edge transitions.
1 increment of clockDelay adds approximately 109 nanoseconds between edges.

SCLAddress

public int SCLAddress
Memory mapped address of the I2C clock line.

SCLMask

public byte SCLMask
Bit mask for clock line within byte at SCLAddress.

SDAAddress

public int SDAAddress
Memory mapped address of the I2C data line.

SDAMask

public byte SDAMask
Bit mask for data line within byte at SDAAddress.
Constructor Detail

I2CPort

public I2CPort()
Use processor port pins for SCL and SDA. On the DS80C390 use P5.0 for SCL and P5.1 for SDA. On DS80C400 use P1.1 for SCL and P1.0 for SDA.

I2CPort

public I2CPort(int SCLAddress,
               byte SCLMask,
               int SDAAddress,
               byte SDAMask)
Use memory mapped IO address for SCL and SDA pins.
Parameters:
SCLAddress - address of latch.
SCLMask - mask of bit or bits to use.
SDAAddress - address of latch.
SDAMask - mask of bit or bits to use.
Method Detail

setAddress

public void setAddress(byte address)
Sets the I2C slave address. This address will take effect on the next read or write. Right justified, least significant bit of this byte == least significant bit of I2C slave address excluding the write/read bit. If the I2C device has an address of 1010101, the address passed to this function would be 0x55.
Parameters:
address - address of I2C slave device.

setClockDelay

public void setClockDelay(byte delay)
Sets how long to wait between I2C edge transitions.
1 increment of clockDelay adds approximately 109 nanoseconds between edges.
Parameters:
delay - I2C Clock delay

setStretchCycles

public void setStretchCycles(byte stretch)
                      throws java.lang.IllegalArgumentException
Sets the number of stretch memory cycles to use when accessing memory mapped IO. Valid values are:
STRETCH0
STRETCH1
STRETCH2
STRETCH3
STRETCH7
STRETCH8
STRETCH9
STRETCH10
Parameters:
stretch - stretch cycle value
Throws:
java.lang.IllegalArgumentException - if stretch is out of range

getStretchCycles

public int getStretchCycles()
Gets the number of stretch memory cycles to use when accessing memory mapped IO.
Returns:
stretch cycle value

write

public int write(byte[] barr,
                 int off,
                 int len)
          throws IllegalAddressException
Writes the byte array to the current slave address
Parameters:
barr - array of bytes to send
off - starting offset to send
len - length of bytes to send
Returns:
bytes read, or -1 on error (No ACK from I2C device)
Throws:
IllegalAddressException - if SCLAddress or SDAAddress is out of range

read

public int read(byte[] barr,
                int off,
                int len)
         throws IllegalAddressException
Reads into the byte array from the current slave address
Parameters:
barr - array to fill from read operation
off - starting offset to read into
len - length of bytes to read
Returns:
bytes read, or -1 on error (No ACK from I2C device)
Throws:
IllegalAddressException - if SCLAddress or SDAAddress is out of range

writeread

public int writeread(byte[] wbarr,
                     int woff,
                     int wlen,
                     byte[] rbarr,
                     int roff,
                     int rlen)
              throws IllegalAddressException
Writes and then reads from/into the byte arrays from the current slave address
Parameters:
wbarr - array to write
woff - starting offset to write from
wlen - length of bytes to write
rbarr - array to fill from read operation
roff - starting offset to read into
rlen - length of bytes to read
Returns:
bytes read, or -1 on error (No ACK from I2C device)
Throws:
IllegalAddressException - if SCLAddress or SDAAddress is out of range


Also see:
o TINI 1.16 API
o TINI Home Page
o 1-Wire API

o JDK 1.1

Last update Wed Jun 8 17:19:36 CDT 2005