Permalink
Browse files

Revert "SRAM SPI Library Example"

This reverts commit 28bdcb8.
  • Loading branch information...
Rei Vilo
Rei Vilo committed Dec 22, 2012
1 parent 28bdcb8 commit 1d9499cb3112d590f985e7a07abed60a5d635951
@@ -1,24 +0,0 @@
-
- SRAM_main
- Project
- ----------------------------------
- Developed with embedXcode
-
- Project SRAM_main
- Created by Rei VILO on déc. 22, 2012
- Copyright © 2012 embedXcode.weebly.com
- Licence CC = BY SA NC
-
-
- References
- ----------------------------------
-
-
-
- embedXcode
- ----------------------------------
- Embedded Computing Template on Xcode 4
- Copyright © Rei VILO, 2010-2012
- Licence CC = BY NC SA
- http://embedXcode.weebly.com/
-
@@ -1,76 +0,0 @@
-//
-// SRAM.cpp
-// Library C++ code
-// ----------------------------------
-// Developed with embedXcode
-// http://embedXcode.weebly.com
-//
-// Project chipKIT_SRAM
-//
-// Created by Rei VILO, déc. 22, 2012 14:26
-// embedXcode.weebly.com
-//
-//
-// Copyright © Rei VILO, 2012
-// Licence CC = BY NC SA
-//
-// See SRAM.cpp.h and ReadMe.txt for references
-//
-
-
-#include "SRAM.h"
-
-SRAM::SRAM(uint8_t pinChipSelect) {
- _pinChipSelect = pinChipSelect;
-}
-
-void SRAM::begin() {
- pinMode(_pinChipSelect, OUTPUT);
- setMode(SRAM_SEQUENCE_MODE);
-}
-
-void SRAM::setMode(uint8_t mode) {
- digitalWrite(_pinChipSelect, LOW);
- SPI.transfer(SRAM_WRITE_STATUS);
- SPI.transfer(mode);
- digitalWrite(_pinChipSelect, HIGH);
-}
-
-uint8_t SRAM::getMode() {
- digitalWrite(_pinChipSelect, LOW);
- SPI.transfer(SRAM_READ_STATUS);
- uint8_t v = SPI.transfer(0);
- digitalWrite(_pinChipSelect, HIGH);
- return v;
-}
-
-void SRAM::write(uint16_t address, uint8_t * data, uint16_t length) {
- if (length>0) {
- digitalWrite(_pinChipSelect, LOW);
- SPI.transfer(SRAM_WRITE);
- SPI.transfer(address >> 8);
- SPI.transfer(address & 0xFF);
- for (uint16_t j=0; j<length; j++) SPI.transfer(data[j]);
- digitalWrite(_pinChipSelect, HIGH);
- }
-}
-
-void SRAM::read(uint16_t address, uint8_t * data, uint16_t length) {
- if (length>0) {
- digitalWrite(_pinChipSelect, LOW);
- SPI.transfer(SRAM_READ);
- SPI.transfer(address >> 8);
- SPI.transfer(address & 0xFF);
-
-#ifdef __MSP430G2553__
- ///
- /// @note Surprisingly with the MSP430G2553, this seems to be required!
- ///
- data[0] = SPI.transfer(0);
-#endif
-
- for (uint16_t j=0; j<length; j++) data[j] = SPI.transfer(0);
-
- digitalWrite (_pinChipSelect, HIGH);
- }
-}
@@ -1,51 +0,0 @@
-///
-/// @file SRAM.h
-/// @brief Library header
-///
-/// @details Library for 23K640 SPI SRAM
-/// @n
-/// @n @b Project chipKIT_SRAM
-/// @n @a Developed with [embedXcode](http://embedXcode.weebly.com)
-///
-/// @author Rei VILO
-/// @author embedXcode.weebly.com
-/// @date déc. 22, 2012 14:26
-/// @version 101
-///
-/// @copyright © Rei VILO, 2012
-/// @copyright CC = BY NC SA
-///
-/// @see ReadMe.txt for references
-///
-// Core library - IDE-based
-#if defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
-#include "Energia.h"
-#else
-#error Platfrom not supported.
-#endif // end IDE
-#ifndef chipKIT_SRAM_SRAM_h
-#define chipKIT_SRAM_SRAM_h
-#include "SPI.h"
-#define SRAM_READ 0b00000011
-#define SRAM_WRITE 0b00000010
-#define SRAM_READ_STATUS 0b00000101
-#define SRAM_WRITE_STATUS 0b00000001
-#define SRAM_BYTE_MODE 0b00000000
-#define SRAM_PAGE_MODE 0b10000000
-#define SRAM_SEQUENCE_MODE 0b01000000
-#define SRAM_RESERVED_MODE 0b11000000
-#define SRAM_HOLD_MODE 0b00000001
-class SRAM {
-public:
- SRAM(uint8_t pinChipSelect);
- void begin();
- void setMode(uint8_t mode);
- uint8_t getMode();
-// void write(uint16_t address, uint8_t data);
- void write(uint16_t address, uint8_t * data, uint16_t length);
-// void read(uint16_t address, uint8_t data);
-void read(uint16_t address, uint8_t * data, uint16_t length);
-private:
- uint8_t _pinChipSelect;
-};
-#endif
@@ -1,188 +0,0 @@
-///
-/// @mainpage SRAM
-///
-/// @details Library for 23K640 SPI SRAM
-/// @n Microchip 23K640 is a SPI 64Kb = 8KB SRAM
-/// @n
-/// @n @a Developed with [embedXcode](http://embedXcode.weebly.com)
-///
-/// @author Rei VILO
-/// @author embedXcode.weebly.com
-/// @date déc. 22, 2012 14:26
-/// @version 101
-///
-/// @copyright © Rei VILO, 2012
-/// @copyright CC = BY NC SA
-///
-/// @see ReadMe.txt for references
-/// * 23A640/23K640 64K SPI Bus Low-Power Serial SRAM Data Sheet
-/// @n http://ww1.microchip.com/downloads/en/DeviceDoc/22126E.pdf
-/// * Recommended Usage of Microchip 23X256/23X640 SPI Serial SRAM Devices
-/// @n http://ww1.microchip.com/downloads/en/AppNotes/01245C.pdf
-
-///
-/// @file SRAM_main.ino
-/// @brief Main sketch
-/// @n This example
-/// * prints 130 columns, saves them into the SRAM,
-/// * then reads them back from SRAM and prints them again.
-///
-/// @details 101
-/// @n @a Developed with [embedXcode](http://embedXcode.weebly.com)
-///
-/// @author Rei VILO
-/// @author embedXcode.weebly.com
-/// @date déc. 22, 2012 14:26
-/// @version 101
-///
-/// @copyright © Rei VILO, 2012
-/// @copyright CC = BY NC SA
-///
-/// @see ReadMe.txt for references
-/// @n
-///
-
-
-#include "Energia.h"
-
-
-// Core library for code-sense
-#if defined(WIRING) // Wiring specific
-#include "Wiring.h"
-#elif defined(MAPLE_IDE) // Maple specific
-#include "WProgram.h"
-#elif defined(MPIDE) // chipKIT specific
-#include "WProgram.h"
-#elif defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
-#include "Energia.h"
-#elif defined(CORE_TEENSY) // Teensy specific
-#include "WProgram.h"
-#elif defined(ARDUINO) && (ARDUINO >= 100) // Arduino 1.0 and 1.5 specific
-#include "Arduino.h"
-#elif defined(ARDUINO) && (ARDUINO < 100) // Arduino 23 specific
-#include "WProgram.h"
-#else // error
-#error Platform not defined
-#endif
-
-// Include application, user and local libraries
-#include "SPI.h"
-#include "SRAM.h"
-
-// Define variables and constants
-
-// Core library for code-sense
-#include "Energia.h"
-
-// Include application, user and local libraries
-#include "SPI.h"
-#include "SRAM.h"
-
-// Define variables and constants
-#if defined(__MSP430G2553__)
-SRAM mySRAM(P1_4); // chip select on pin P1_4
-#elif defined(__LM4F120H5QR__)
-SRAM mySRAM(PE_5); // chip select on pin PE_5
-#else
-#error Board not supported
-#endif
-
-const uint16_t MAX = 130;
-uint8_t modulo = 26;
-char buffer[MAX];
-uint8_t i = 'A';
-
-void setup (void)
-{
- ///
- /// @note SPI speed difference
- /// * SPI_CLOCK_DIV2 for MSP430G2553 gives 8 MHz
- /// * SPI_CLOCK_DIV2 for LM4F120H5QR gives 4 MHz!
- ///
- /// @warning SPI maximum speed
- /// * SPI_CLOCK_DIV8 for MSP430G2553
- /// * SPI_CLOCK_DIV2 for LM4F120H5QR
- ///
-
-#if defined(__MSP430G2553__)
- SPI.begin();
- // SPI.setClockDivider(SPI_CLOCK_DIV2); // for MSP430G2553 DIV2 = 8 MHz
- SPI.setClockDivider(SPI_CLOCK_DIV8); // for MSP430G2553
-#elif defined(__LM4F120H5QR__)
- SPI.begin(2);
- SPI.setClockDivider(SPI_CLOCK_DIV2); // for LM4F120H5QR = 4 MHz !
-#endif
-
- mySRAM.begin();
-
- // For the example
- Serial.begin (9600);
- Serial.println("*** start");
- Serial.println("*** PUSH2 to close serial");
- Serial.println();
-
- if (MAX < modulo) modulo = MAX;
- pinMode(PUSH2, INPUT_PULLUP);
-
- Serial.print(" :");
- for (uint8_t j=0; j<MAX; j++) {
- if ( ((j+1) % 10==0) && ((j+1)/100>0) ) Serial.print((j+1)/100, DEC);
- else Serial.print(" ");
- }
- Serial.println();
-
- Serial.print(" :");
- for (uint8_t j=0; j<MAX; j++) {
- if ((j+1) % 10==0) Serial.print(((j+1)/10) %10, DEC);
- else Serial.print(" ");
- }
- Serial.println();
-
- Serial.print(" :");
- for (uint8_t j=0; j<MAX; j++) {
- if ((j+1) % 10==0) Serial.print("0");
- else Serial.print(" ");
- }
- Serial.println();
-}
-
-
-void loop (void)
-{
- Serial.print("write >");
- for (uint8_t j=0; j<MAX; j++) {
- buffer[j]='.';
- if ((j % modulo)+ 'A' == i) buffer[j]=i;
- Serial.print((char)buffer[j]);
- }
- Serial.println();
-
- i++;
- if (i>modulo+'A') i = 'A';
-
- mySRAM.write(100, (uint8_t *) buffer, sizeof buffer);
-
- for (uint8_t j=0; j<MAX; j++) buffer[j]=0;
-
- Serial.print("read <");
- mySRAM.read(100, (uint8_t *) buffer, MAX);
-
- for (uint8_t j=0; j<MAX; j++) {
- Serial.print((char)buffer[j]);
- }
- Serial.println();
- delay(1000);
-
- if (!digitalRead(PUSH2)) {
- Serial.print("*** ");
- while (!digitalRead(PUSH2));
- Serial.println("end");
- Serial.end();
- while (true) delay(100);
-
- }
-}
-
-
-
-

0 comments on commit 1d9499c

Please sign in to comment.