Library to drive the Microchip 23K256 SRAM over SPI.

Dependencies:   mbed

Ser23K256.h

Committer:
romilly
Date:
2010-08-15
Revision:
2:f96c3c85aa3b
Child:
3:d2314b1ac797

File content as of revision 2:f96c3c85aa3b:

// Ser23K256 - drive the Microchip 23K256 SRAM using SPI
// Copyright (c) 2010 Romilly Cocking
// Released under the MIT License: http://mbed.org/license/mit

#include "mbed.h"

#ifndef  SER23K256_H
#define  SER23K256_H

// mode codes for 23K256
#define BYTE_MODE       0x00
#define SEQUENTIAL_MODE 0x40

// command codes for 23K256
#define READ            0x03
#define WRITE           0x02
#define READ_STATUS     0x05 // called RDSR in datasheet
#define WRITE_STATUS    0x01 // called WRSR in datasheet

class Ser23K256 {
public:
    Ser23K256(SPI& spi, PinName ncs);
    char read(int address);
    void read(int address, char * buffer, int count);
    void write(int address, char byte);
    void write(int address, char * buffer, int count);
private:
    SPI& _spi;
    DigitalOut _ncs;
    char readStatus();
    void writeStatus(char status);
    void prepareCommand(char command, int address);
    void select();
    void deselect();
};

#endif