Cypress F-RAM FM25W256 library

Dependents:   Hello-FM25W256 Hello-FM25W256

Committer:
MACRUM
Date:
Fri Mar 04 15:49:51 2016 +0000
Revision:
0:5a552209903c
Child:
1:bb2b1e4bfb6e
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:5a552209903c 1 #include "mbed.h"
MACRUM 0:5a552209903c 2 #include "FM25W256.h"
MACRUM 0:5a552209903c 3
MACRUM 0:5a552209903c 4 FM25W256::FM25W256(PinName mosi, PinName miso, PinName clk, PinName cs)
MACRUM 0:5a552209903c 5 : _spi(mosi, miso, clk), _cs(cs)
MACRUM 0:5a552209903c 6 {
MACRUM 0:5a552209903c 7 _spi.format(8, 0);
MACRUM 0:5a552209903c 8 _spi.frequency(20000000);
MACRUM 0:5a552209903c 9 _cs = 1;
MACRUM 0:5a552209903c 10 }
MACRUM 0:5a552209903c 11
MACRUM 0:5a552209903c 12 FM25W256::FM25W256(SPI &spi, PinName cs)
MACRUM 0:5a552209903c 13 : _spi(spi), _cs(cs)
MACRUM 0:5a552209903c 14 {
MACRUM 0:5a552209903c 15 _spi.format(8, 0);
MACRUM 0:5a552209903c 16 _spi.frequency(20000000);
MACRUM 0:5a552209903c 17 _cs = 1;
MACRUM 0:5a552209903c 18
MACRUM 0:5a552209903c 19 }
MACRUM 0:5a552209903c 20
MACRUM 0:5a552209903c 21 void FM25W256::write(uint16_t address, uint8_t data)
MACRUM 0:5a552209903c 22 {
MACRUM 0:5a552209903c 23 _cs = 0;
MACRUM 0:5a552209903c 24 _spi.write(CMD_WREN);
MACRUM 0:5a552209903c 25 _cs = 1;
MACRUM 0:5a552209903c 26
MACRUM 0:5a552209903c 27 _cs = 0;
MACRUM 0:5a552209903c 28 _spi.write(CMD_WRITE);
MACRUM 0:5a552209903c 29 _spi.write(address >> 8);
MACRUM 0:5a552209903c 30 _spi.write(address & 0xFF);
MACRUM 0:5a552209903c 31 _spi.write(data);
MACRUM 0:5a552209903c 32 _cs = 1;
MACRUM 0:5a552209903c 33 }
MACRUM 0:5a552209903c 34
MACRUM 0:5a552209903c 35 void FM25W256::write(uint16_t address, uint8_t *data, uint16_t size)
MACRUM 0:5a552209903c 36 {
MACRUM 0:5a552209903c 37 _cs = 0;
MACRUM 0:5a552209903c 38 _spi.write(CMD_WREN);
MACRUM 0:5a552209903c 39 _cs = 1;
MACRUM 0:5a552209903c 40
MACRUM 0:5a552209903c 41 _cs = 0;
MACRUM 0:5a552209903c 42 _spi.write(CMD_WRITE);
MACRUM 0:5a552209903c 43 _spi.write(address >> 8);
MACRUM 0:5a552209903c 44 _spi.write(address & 0xFF);
MACRUM 0:5a552209903c 45 while(size--) {
MACRUM 0:5a552209903c 46 _spi.write(*data++);
MACRUM 0:5a552209903c 47 }
MACRUM 0:5a552209903c 48 _cs = 1;
MACRUM 0:5a552209903c 49 }
MACRUM 0:5a552209903c 50
MACRUM 0:5a552209903c 51 uint8_t FM25W256::read(uint16_t address)
MACRUM 0:5a552209903c 52 {
MACRUM 0:5a552209903c 53 uint8_t data;
MACRUM 0:5a552209903c 54
MACRUM 0:5a552209903c 55 _cs = 0;
MACRUM 0:5a552209903c 56 _spi.write(CMD_READ);
MACRUM 0:5a552209903c 57 _spi.write(address >> 8);
MACRUM 0:5a552209903c 58 _spi.write(address & 0xFF);
MACRUM 0:5a552209903c 59 data = _spi.write(0);
MACRUM 0:5a552209903c 60 _cs = 1;
MACRUM 0:5a552209903c 61
MACRUM 0:5a552209903c 62 return data;
MACRUM 0:5a552209903c 63 }
MACRUM 0:5a552209903c 64
MACRUM 0:5a552209903c 65 void FM25W256::read(uint16_t address, uint8_t *buf, uint16_t size)
MACRUM 0:5a552209903c 66 {
MACRUM 0:5a552209903c 67 _cs = 0;
MACRUM 0:5a552209903c 68 _spi.write(CMD_READ);
MACRUM 0:5a552209903c 69 _spi.write(address >> 8);
MACRUM 0:5a552209903c 70 _spi.write(address & 0xFF);
MACRUM 0:5a552209903c 71 while (size--) {
MACRUM 0:5a552209903c 72 *buf++ = _spi.write(0);
MACRUM 0:5a552209903c 73 }
MACRUM 0:5a552209903c 74 _cs = 1;
MACRUM 0:5a552209903c 75 }