de.wagner_ibw.iow.spi
Class M95020

java.lang.Object
  |
  +--de.wagner_ibw.iow.spi.AbstractSPIDevice
        |
        +--de.wagner_ibw.iow.spi.M95020
All Implemented Interfaces:
SPIDevice

public class M95020
extends AbstractSPIDevice

Implemenation of the M95020 (2Kbit EEPROM) spi device. Tested successfully with 1MBit/sec spi SCK.

Since:
0.9.4.
Author:
Thomas Wagner

Field Summary
static int CMD_RDSR
          Instruction "Read Status Register".
static int CMD_READ
          Instruction "Read to Memory Array".
static int CMD_WRDI
          Instruction "Write Disable".
static int CMD_WREN
          Instruction "Write Enable".
static int CMD_WRITE
          Instruction "Write to Memory Array".
static int CMD_WRSR
          Instruction "Write Status Register".
 int EEPROM_SIZE
          Capacity of this EEPROM in byte.
static int FLAGS
          Prefered SPI special mode function flags for this device.
 int MAX_PAGE_SIZE
          Maximum page size for block write operations.
static java.lang.String NAME
          M95020 device specific constants.
 
Constructor Summary
M95020()
          Constructor.
 
Method Summary
 void fillEeprom(int pattern)
          Fills the whole eeprom with the specified pattern.
 int read(int address)
          Reads Memory Array at the specified address.
 int[] readPage(int address, int length)
          Reads more than one value from the Memory array.
 int readStatusReg()
          Reads the eeprom's status register.
 void write(int address, int data)
          Writes Memory Array at the specified address.
 void writeDisable()
          Disables write operations.
 void writeEnable()
          Enables write operations.
 void writePage(int address, int[] data)
          Writes more than one value to the Memory array.
 void writeStatusReg(int statusRegister)
          Writes a new value to the eeprom's status register.
 
Methods inherited from class de.wagner_ibw.iow.spi.AbstractSPIDevice
getName, reportReceived, setIowDevice, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME

public static final java.lang.String NAME
M95020 device specific constants.

See Also:
Constant Field Values

MAX_PAGE_SIZE

public final int MAX_PAGE_SIZE
Maximum page size for block write operations.

See Also:
Constant Field Values

EEPROM_SIZE

public final int EEPROM_SIZE
Capacity of this EEPROM in byte.

See Also:
Constant Field Values

CMD_WREN

public static final int CMD_WREN
Instruction "Write Enable".

See Also:
Constant Field Values

CMD_WRDI

public static final int CMD_WRDI
Instruction "Write Disable".

See Also:
Constant Field Values

CMD_RDSR

public static final int CMD_RDSR
Instruction "Read Status Register".

See Also:
Constant Field Values

CMD_WRSR

public static final int CMD_WRSR
Instruction "Write Status Register".

See Also:
Constant Field Values

CMD_READ

public static final int CMD_READ
Instruction "Read to Memory Array".

See Also:
Constant Field Values

CMD_WRITE

public static final int CMD_WRITE
Instruction "Write to Memory Array".

See Also:
Constant Field Values

FLAGS

public static final int FLAGS
Prefered SPI special mode function flags for this device.

See Also:
Constant Field Values
Constructor Detail

M95020

public M95020()
Constructor.

Method Detail

writeEnable

public void writeEnable()
                 throws java.lang.Exception
Enables write operations.

Throws:
java.lang.Exception - If any transmission error occurred.

writeDisable

public void writeDisable()
                  throws java.lang.Exception
Disables write operations.

Throws:
java.lang.Exception - If any transmission error occurred.

read

public int read(int address)
         throws java.lang.Exception
Reads Memory Array at the specified address.

Parameters:
address - Read address.
Returns:
The content at the specified address.
Throws:
java.lang.Exception - If any transmission error occurred.
java.lang.IllegalArgumentException - If address is invalid.

write

public void write(int address,
                  int data)
           throws java.lang.Exception,
                  java.lang.IllegalArgumentException
Writes Memory Array at the specified address.

Parameters:
address - Write address.
data - Value to write.
Throws:
java.lang.Exception - If any transmission error occurred.
java.lang.IllegalArgumentException - If address is invalid.

writePage

public void writePage(int address,
                      int[] data)
               throws java.lang.Exception,
                      java.lang.IllegalArgumentException
Writes more than one value to the Memory array. Maximum page size is MAX_PAGE_SIZE (16).

Parameters:
address - Start write address.
data - Array of values to write.
Throws:
java.lang.Exception - If any transmission error occurred.
java.lang.IllegalArgumentException - If address is invalid or if array size is out of range (1...MAX_PAGE_SIZE).

readPage

public int[] readPage(int address,
                      int length)
               throws java.lang.Exception,
                      java.lang.IllegalArgumentException
Reads more than one value from the Memory array. Maximum page size is 256 (whole eeprom).

Parameters:
address - Start read address.
length - How many values to read.
Returns:
result Array of readed values.
Throws:
java.lang.Exception - If any transmission error occurred.
java.lang.IllegalArgumentException - If address is invalid.

writeStatusReg

public void writeStatusReg(int statusRegister)
                    throws java.lang.Exception
Writes a new value to the eeprom's status register.

Parameters:
statusRegister - New value for the register.
Throws:
java.lang.Exception - If any transmission error occurred.

readStatusReg

public int readStatusReg()
                  throws java.lang.Exception
Reads the eeprom's status register. Bit 7...4 are always set to 1.

Returns:
value of the status register.
Throws:
java.lang.Exception - If any transmission error occurred.

fillEeprom

public void fillEeprom(int pattern)
                throws java.lang.Exception
Fills the whole eeprom with the specified pattern.

Parameters:
pattern - Pattern that fills the eeprom.
Throws:
java.lang.Exception - If any transmission error occurred.