EmbeddedArtists AB
/
lpc812_exp_solution_spi-e2prom
Solutions for the SPI E2PROM experiments for LPC812 MAX
SPI25LC080.h@1:819f21483c01, 2013-11-28 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Nov 28 12:17:45 2013 +0000
- Revision:
- 1:819f21483c01
- Parent:
- SPI24LC080.h@0:aa38ad0bf51d
Renamed the SPI24LC080 class to SPI25LC080 as it is an interface to the 25LC080 chip.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 1:819f21483c01 | 1 | #ifndef SPI25LC080_H |
embeddedartists | 1:819f21483c01 | 2 | #define SPI25LC080_H |
embeddedartists | 0:aa38ad0bf51d | 3 | |
embeddedartists | 0:aa38ad0bf51d | 4 | /** |
embeddedartists | 1:819f21483c01 | 5 | * Interface to the 25LC080 chip (http://ww1.microchip.com/downloads/en/DeviceDoc/22151b.pdf) |
embeddedartists | 0:aa38ad0bf51d | 6 | * |
embeddedartists | 0:aa38ad0bf51d | 7 | * @code |
embeddedartists | 0:aa38ad0bf51d | 8 | * #include "mbed.h" |
embeddedartists | 0:aa38ad0bf51d | 9 | * |
embeddedartists | 1:819f21483c01 | 10 | * SPI25LC080 e2prom; |
embeddedartists | 0:aa38ad0bf51d | 11 | * |
embeddedartists | 0:aa38ad0bf51d | 12 | * int main(void) { |
embeddedartists | 0:aa38ad0bf51d | 13 | * uint8_t buff[20]; |
embeddedartists | 0:aa38ad0bf51d | 14 | * uint16_t addr = ... |
embeddedartists | 0:aa38ad0bf51d | 15 | * |
embeddedartists | 0:aa38ad0bf51d | 16 | * while(1) { |
embeddedartists | 0:aa38ad0bf51d | 17 | * // read from e2prom |
embeddedartists | 0:aa38ad0bf51d | 18 | * e2prom.read(addr, buff, 20); |
embeddedartists | 0:aa38ad0bf51d | 19 | * |
embeddedartists | 0:aa38ad0bf51d | 20 | * // write to e2prom |
embeddedartists | 0:aa38ad0bf51d | 21 | * e2prom.write(addr, buff, 20); |
embeddedartists | 0:aa38ad0bf51d | 22 | * } |
embeddedartists | 0:aa38ad0bf51d | 23 | * } |
embeddedartists | 0:aa38ad0bf51d | 24 | * @endcode |
embeddedartists | 0:aa38ad0bf51d | 25 | */ |
embeddedartists | 1:819f21483c01 | 26 | class SPI25LC080 { |
embeddedartists | 0:aa38ad0bf51d | 27 | public: |
embeddedartists | 0:aa38ad0bf51d | 28 | |
embeddedartists | 1:819f21483c01 | 29 | /** Create an interface to the 25LC080 chip |
embeddedartists | 0:aa38ad0bf51d | 30 | * |
embeddedartists | 0:aa38ad0bf51d | 31 | * @param mosi the SPI MOSI pin |
embeddedartists | 0:aa38ad0bf51d | 32 | * @param sclk the SPI SCLK pin |
embeddedartists | 0:aa38ad0bf51d | 33 | * @param miso the SPI MISO pin |
embeddedartists | 0:aa38ad0bf51d | 34 | */ |
embeddedartists | 1:819f21483c01 | 35 | SPI25LC080(PinName mosi = P0_14, PinName sclk = P0_12, PinName miso = P0_15, PinName ssel = P0_13); |
embeddedartists | 0:aa38ad0bf51d | 36 | |
embeddedartists | 0:aa38ad0bf51d | 37 | /** Reads from the E2PROM |
embeddedartists | 0:aa38ad0bf51d | 38 | * |
embeddedartists | 0:aa38ad0bf51d | 39 | * @param address the address to read from |
embeddedartists | 0:aa38ad0bf51d | 40 | * @param pBuf where to store the read data |
embeddedartists | 0:aa38ad0bf51d | 41 | * @param length the number of bytes to read |
embeddedartists | 0:aa38ad0bf51d | 42 | */ |
embeddedartists | 0:aa38ad0bf51d | 43 | void read(uint16_t address, uint8_t* pData, uint32_t length); |
embeddedartists | 0:aa38ad0bf51d | 44 | |
embeddedartists | 0:aa38ad0bf51d | 45 | /** Writes to the E2PROM |
embeddedartists | 0:aa38ad0bf51d | 46 | * |
embeddedartists | 0:aa38ad0bf51d | 47 | * @param address the address to write to |
embeddedartists | 0:aa38ad0bf51d | 48 | * @param pBuf the data to write |
embeddedartists | 0:aa38ad0bf51d | 49 | * @param length the number of bytes to write |
embeddedartists | 0:aa38ad0bf51d | 50 | */ |
embeddedartists | 0:aa38ad0bf51d | 51 | void write(uint16_t address, uint8_t* pData, uint32_t length); |
embeddedartists | 0:aa38ad0bf51d | 52 | |
embeddedartists | 0:aa38ad0bf51d | 53 | /** Reads the status register |
embeddedartists | 0:aa38ad0bf51d | 54 | */ |
embeddedartists | 0:aa38ad0bf51d | 55 | uint8_t status(); |
embeddedartists | 0:aa38ad0bf51d | 56 | |
embeddedartists | 0:aa38ad0bf51d | 57 | private: |
embeddedartists | 0:aa38ad0bf51d | 58 | SPI m_spi; |
embeddedartists | 0:aa38ad0bf51d | 59 | DigitalOut m_ssel; |
embeddedartists | 0:aa38ad0bf51d | 60 | |
embeddedartists | 0:aa38ad0bf51d | 61 | /** Sets the write enable latch/bit |
embeddedartists | 0:aa38ad0bf51d | 62 | */ |
embeddedartists | 0:aa38ad0bf51d | 63 | void write_enable(); |
embeddedartists | 0:aa38ad0bf51d | 64 | }; |
embeddedartists | 0:aa38ad0bf51d | 65 | |
embeddedartists | 0:aa38ad0bf51d | 66 | #endif |
embeddedartists | 0:aa38ad0bf51d | 67 |