# sram_23k256

23K256 sram library

Author | Matthew Schinkel - borntechi.com, copyright © 2009, all rights reserved.
Adapted-by | Sebastien Lelong
Compiler | >=2.4l

Description

    This is library for 23K256 SPI SRAM, Microchip's 20mhz 256kbit SRAM memory

Sources

    http://ww1.microchip.com/downloads/en/DeviceDoc/22100D.pdf

Notes

    Address from 0 to 32,767
    This is a 2.7v to 3.6v memory.
    This lib should also work with 23k640 (64kbit sram), but hasn't been tested, please let me know.
    Also should work with 23A640 & 23A256 (1.5v to 1.95v versions), also not tested
    SPI Mode is 00 for 23k256

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const byte SRAM_23K256_PAGE_MODE = 0b10`
- `const byte SRAM_23K256_WRITE_SETTINGS = 0b_0000_0001`
- `const byte SRAM_23K256_HOLD_DISABLE = 1`
- `const byte SRAM_23K256_BYTE_MODE = 0b00`
- `const byte SRAM_23K256_READ_COMMAND = 0b_0000_0011`
- `const byte SRAM_23K256_HOLD_ENABLE = 0`
- `const byte SRAM_23K256_WRITE_COMMAND = 0b_0000_0010`
- `const byte SRAM_23K256_SEQUENTIAL_MODE = 0b01`
- `const byte SRAM_23K256_READ_STATUS = 0b_0000_0101`

### Procedures

- `sram_23k256_start_write(word in address)`
- `sram_23k256_init(byte in sram_23k256_mode, byte in sram_23k256_hold_disable)`
- `sram_23k256_byte'put(word in address, byte in data)`
- `sram_23k256_do_read(byte out data)`
- `sram_23k256_dword'put(word in address, dword in data)`
- `sram_23k256_read_settings(byte out mode, byte out hold_is_disabled)`
- `sram_23k256_do_write(byte in data)`
- `sram_23k256_word'put(word in address, word in data)`
- `sram_23k256_write(word in address, byte in data)`
- `sram_23k256_read(word in address, byte out data)`
- `sram_23k256_stop_read()`
- `sram_23k256_start_read(word in address)`
- `sram_23k256_stop_write()`

### Functions

- `sram_23k256_dword'get(word in address) return dword`
- `sram_23k256_word'get(word in address) return word`
- `sram_23k256_byte'get(word in address) return byte`

## API details

### Global variables/contants

- `const byte SRAM_23K256_PAGE_MODE = 0b10`

      send read command then read 1 32Byte page

- `const byte SRAM_23K256_WRITE_SETTINGS = 0b_0000_0001`

      Write STATUS register

- `const byte SRAM_23K256_HOLD_DISABLE = 1`

      disable the hold pin. (connect put pin direct to 3.3v)

- `const byte SRAM_23K256_BYTE_MODE = 0b00`

      constants for use with init procedure input data
      modes in witch to read and write data

- `const byte SRAM_23K256_READ_COMMAND = 0b_0000_0011`

      constants for internal usage

- `const byte SRAM_23K256_HOLD_ENABLE = 0`

      enable the hold pin   (conect pin to microcontroller)

- `const byte SRAM_23K256_WRITE_COMMAND = 0b_0000_0010`

      Write data to memory array beginning at selected address

- `const byte SRAM_23K256_SEQUENTIAL_MODE = 0b01`

      send read command then read many bytes

- `const byte SRAM_23K256_READ_STATUS = 0b_0000_0101`

      Read STATUS register

### Procedures

- `sram_23k256_start_write(word in address)`

      get 23K256 ready for writing and select a address to start from (fast writes)
      do not interupt read process by switching to another spi device

- `sram_23k256_init(byte in sram_23k256_mode, byte in sram_23k256_hold_disable)`

      initialize startup settings & spi mode 00

- `sram_23k256_byte'put(word in address, byte in data)`

      Write to 23k256 as a byte array

- `sram_23k256_do_read(byte out data)`

      read byte from the 23K256

- `sram_23k256_dword'put(word in address, dword in data)`

      Write 23k256 as a large 8K dword array

- `sram_23k256_read_settings(byte out mode, byte out hold_is_disabled)`

      Reads the status/settings register to get the current 23k256 mode
      that was previously set in the init procedure.
      SRAM_23K256_BYTE_MODE, SRAM_23K256_SEQUENTIAL_MODE, SRAM_23K256_PAGE_MODE

- `sram_23k256_do_write(byte in data)`

      write byte to the 23K256
      you may use spi_master directly instead.

- `sram_23k256_word'put(word in address, word in data)`

      Write 23k256 as a large 16K word array

- `sram_23k256_write(word in address, byte in data)`

      Write 1 byte to selected address

- `sram_23k256_read(word in address, byte out data)`

      Read 1 byte to selected address

- `sram_23k256_stop_read()`

      tell 23K256 you are finished reading

- `sram_23k256_start_read(word in address)`

      get 23K256 ready for reading and select a address to start from (fast reads)
      do not interupt read process by switching to another spi device

- `sram_23k256_stop_write()`

      tell 23K256 you are finished writing

### Functions

- `sram_23k256_dword'get(word in address) return dword`

      Read from 23k256 as a large 8K dword array

- `sram_23k256_word'get(word in address) return word`

      Read from 23k256 as a large 16K word array

- `sram_23k256_byte'get(word in address) return byte`

      Read from 23k256 as a byte array

## Related samples

Here are the list of samples which use this library:

16f877 | 16f877_fat32_small_pata_hard_disk.jal
16f877a | 16f877a_fat32_small_pata_hard_disk.jal
16f877a | 16f877a_23k256.jal
18f26j50 | 18f26j50_sd_card.jal
18f26j50 | 18f26j50_fat32_sd_card.jal
18f452 | 18f452_fat32_small_pata_hard_disk.jal
18f452 | 18f452_23k256.jal
18f452 | 18f452_fat32_small_sd_card.jal
18f4525 | 18f4525_fat32_sd_card.jal
18f4525 | 18f4525_mp3_decoder_vs1053b_sd_card.jal
18f4525 | 18f4525_fat32_small_pata_hard_disk.jal
18f4525 | 18f4525_fat32_pata_hard_disk.jal
18f4525 | 18f4525_mp3_decoder_vs1053b_pata_hard_disk.jal
18f4525 | 18f4525_fat32_small_sd_card.jal
18f4550 | 18f4550_fat32_small_sd_card.jal
18f4550 | 18f4550_23k256.jal
18f4620 | 18f4620_mp3_decoder_vs1053b_sd_card.jal
18f4620 | 18f4620_fat32_pata_hard_disk.jal
18f4620 | 18f4620_fat32_small_sd_card.jal
18f4620 | 18f4620_mp3_decoder_vs1053b_pata_hard_disk.jal
18f4620 | 18f4620_fat32_sd_card.jal
18f4620 | 18f4620_fat32_small_pata_hard_disk.jal
18f67j50 | 18f67j50_fat32_pata_hard_disk.jal
18f67j50 | 18f67j50_mp3_decoder_vs1053b_sd_card.jal
18f67j50 | 18f67j50_fat32_small_pata_hard_disk.jal
18f67j50 | 18f67j50_mp3_decoder_vs1053b_pata_hard_disk.jal
18f67j50 | 18f67j50_23k256.jal
18f67j50 | 18f67j50_fat32_sd_card.jal
18f67j50 | 18f67j50_fat32_small_sd_card.jal
18f67j60 | 18f67j60_fat32_sd_card.jal