Giter Site home page Giter Site logo

siktec-epd-board's Introduction

SIKTEC-SRAM

Library for Interfacing Microchip SRAM chips.
Suitable and tested with Microchip 23K256-I/SN should work with most of the chips of the same family and others.


Description

This library seamlessly communcates with SPI based SRAM chips and exposes a simple and lightweight API to interface with an external SRAM chip.
The library is well documented and has 2 examples - You can easily write / read / erase and debug SRAM chips. All SPI communication is managed by the library.
This library can be easily ported to other chips by simply changing the instruction set used by the library.

Physically tested with:

CHIP Manufacturer Datasheet
23K256-I/SN Microchip http://ww1.microchip.com/downloads/en/devicedoc/22100f.pdf

Table of Contents:


Installation:


Return

You can install the library through one of the following:

  1. Arduino or PlatformIO library manager: Search for "SIKTEC_SRAM" and click install.
  2. Download the repositories as a ZIP file and install it through the Arduino IDE by:
    Sketch -> Include library -> Add .ZIP Library.
  3. Download the library and include it in your project folder - Then you can Include it directly:
    #include "{path to}\SIKTEC_SRAM.h"

Dependency When manually including the library you should also import the library dependencies SIKTEC_SPI.h .


Example included:


Return

  • ReadWrite.ino - A simple example that writes an array to SRAM, dumps raw data from the SRAM chip and Reads back the read data.
  • StoreStruct.ino - This example demonstrates how to serialize a structure and store it on the SRAM chip - Also exposes a raw dump of the data and how to deserialize it back to the same type structure.

Declaring of 'SIKTEC_SRAM' object:


Return

Call SIKTEC_SRAM expects a CS (chip select) pin number to initialize with default HardWare SPI - Or pass the SPI pins to be used.
After creating the SIKTEC_SRAM instance the begin() method should be called to start SRAM communication.

#include <SIKTEC_SRAM.h>

...

//using namespace SIKtec; // Optional 

//Define SRAM CS Pin attached:
#define SRAM_CS     17

//Declare SRAM object:
SIKtec::SIKTEC_SRAM sram(SRAM_CS);

void setup() {
    
    ...
    
    //Start SRAM Communication
    sram.begin();

    //Set the SRAM chip array Mode:
    if (!sram.set_mode(SRAM_MODE::SRAM_SEQ_MODE)) {
        Serial.print("SRAM MODE FAILED");
    }
    ...
}
...
  • Note: SIKTEC_SRAM depends on SIKTEC_SPI which is an SPI wrapper that improves the SPI api.
  • Note: Its a good practice to add a pull-up ressistor to the CS pin.
  • Note: Three MODES are available - SRAM_SEQ_MODE, SRAM_PAGE_MODE, SRAM_BYTE_MODE - read more about those modes in the datasheet.

Writing to SRAM:


Return

By default the library doesn't set any default data on the SRAM - Its full of garbage.
To write data you should use the write() passing it a start address, a buffer of data, and the size to write.
Address space starts at 0x0000 and ends depending on the SRAM size.

    ...
    
    //Write a single byte:
    uint8_t single = 7;
    sram.write8(0x0000, single); // will occupy 0x0000

    //Write a uint16:
    uint16_t single = 1700;
    sram.write16(0x0001, single); // will occupy 0x0001, 0x0002

    //Array write:
    uint8_t data[] = {1, 2, 3, 4, 5};
    sram.write(0x0003, data, sizeof(data)); // will occupy 0x0003 -> 0x0007

    ...

Note: If an overflow occurs the SRAM chip will loop back to the 0x00 and write there.


Reading from SRAM


Return

To read data you should use the object read() methods passing it the starting address and a buffer to write to with the requested length.

    ...

    //Read a single byte:
    uint8_t single8 = sram.read8(0x0000);

    //Read a uint16:
    uint16_t single16 = sram.read16(0x0001); // will basically read 0x1 and 0x2 and returns a uint16 number

    //Read to buffer:
    uint8_t data[10];
    sram.read(0x0003, data, sizeof(data));

    ...

Note: Even if you did not write data to those addresses SRAM will return data - It will be garbage data set by default.


Erasing data on the SRAM


Return

There is no real data erasing - The trick is to set the data to a default value which we consider as "erased". The default value used by the method is 0x00 but you can use your own - To erase you should use the erase() method.

    ...

    //Erase:
    sram.erase(0x0000, 2); // 0x0 and 0x1 will be set to 0.

    sram.erase(0x0000, 2, 0x1); // 0x0 and 0x1 will be set to 1.

    ...

Debugging:


Return

The library has two debugging methods print_status(), mem_dump() - Those methods expects a Stream instance By default will use the Serial instance included by Arduino.

    ...

    /*  
    void mem_dump(
        uint16_t from, 
        uint16_t length, 
        bool address = true, 
        bool decimal = true, 
        bool hex = true, 
        bool binary = true, 
        Stream *serialport = &Serial
    );
    */

    sram.mem_dump(0x0000, 2);
    /*
    Will print data written on sram:
    SRAM [0x0] => 100 , 0x64 , 1100100
    SRAM [0x1] => 0 , 0x0 , 0
    */

    sram.print_status(0x0000, 2);
    /*
    Will print:
    SRAM STATUS REGISTER - 64 [1000000]
    */

    ...

By default mem_dump() will print data in 3 formats dec, hex, bin - you can disable those formats with the flags passed to mem_dump.


Additional notes:


Return

  1. The library has more methods which exposes a lower level that gives you control over the CS pin state - Its usefull especially when you want to bridge data between the SRAM chip to another connected SPI device directly.
  2. For more advance usage and storing structs use the examples which are commented and provides more real-world usage of this library.

siktec-epd-board's People

Contributors

shlomohass avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.