Pages: [1]   Go Down
Author Topic: Problems understaning SPI and Reading EEPROM  (Read 317 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 91
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

MOVED
I moved this to Networking, etc as I think it is more appropriate there
http://arduino.cc/forum/index.php/topic,151250.0.html
thanks


i really helpful people of the forum,

Im stuck again.
I have a 93LC46 EEPROM that i would like to read and write to. Read first, then write. Walk before run. I would think that there is already data in it as it has been salvaged from an old NIC.

I have been reading up on SPI on the library page and about its commands. Also have been going over the datasheet for the device.
link: http://ww1.microchip.com/downloads/en/devicedoc/21712b.pdf
and this document: http://mcu.sunplusmcu.com/soft/65_en_Application_note/AN_SPMC65_O0323_en_V1.2.pdf
Also i have been trying to learn from and adapt info from this page:
http://arduino.cc/en/Tutorial/SPIEEPROM
Ive tried his sketch, but im afraid that there are differences in the chips.

I have hooked up the arduino like this:
Arduino   93LC46
pin10   ->  pin1               (select)
pin11   ->  pin3               (MOSI  ->  DI)
pin12   ->  pin4               (MISO  ->  DO)
pin13   ->  pin2               (CLK   ->  CLK)
               pin5  -> gnd    (gnd)
               pin6  -> gnd    (Org)
               pin7  -> nc
               pin8  -> 5v

I read in the datasheet that you have to first send it a startup command (CS and DI HIGH) before it will accept any inputs (read, write, clear, etc).
Im not sure how to do this, can it be just digitalWriting those pins high then LOW again.

Next problem, all the SPI stuff i read says that CS is when the pin is pulled low. In the datasheet, though, its opposite.

Now the biggest problem, I dont understand the code to read and write to it. I have to send it a "1" to signify that a command is coming, then the command ("10" for read and "01" for write) then it will want the address. (page 4 of datasheet)
All the examples SPI sketches show something like this:
Code:
const byte READ = 0b11111100;     // SCP1000's read command
const byte WRITE = 0b00000010;   // SCP1000's write command
how do i get to that sort of format, do i need to, why is there a 'b' in there?

Heres the code i have been playing with all night, I know it looks like i have no idea what im doing with this and thats because i dont.
Code:
/*
 Circuit:
 MOSI: pin 11
 MISO: pin 12
 SCK: pin 13

 */

// the sensor communicates using SPI, so include the library:
#include <SPI.h>

const int chipSelectPin = 10;

void setup() {
  Serial.begin(9600);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
  delay(100);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  
  // start the SPI library:
  SPI.begin();
  
  // initalize the  data ready and chip select pins:
  pinMode(chipSelectPin, OUTPUT);
  delay(100);
}

void loop() {


  // don't do anything until the data ready pin is Low:
 
      digitalWrite(chipSelectPin, HIGH);
       SPI.transfer(0x1);
       SPI.transfer(0x10);
       int tempData = SPI.transfer(A6);
    // take the chip select low to de-select:
      digitalWrite(chipSelectPin, LOW);

  

    // display the tempdata:
    Serial.println(tempData);
    delay(500);
  }



Any help to get even a little bit closer to understanding this would be great!

« Last Edit: February 27, 2013, 11:51:41 am by gr0p3r » Logged

Pages: [1]   Go Up
Jump to: