Go Down

Topic: Problems understaning SPI and Reading EEPROM (Read 1 time) previous topic - next topic


Feb 27, 2013, 05:29 pm Last Edit: Feb 27, 2013, 05:51 pm by gr0p3r Reason: 1
I moved this to Networking, etc as I think it is more appropriate there

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:
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: [Select]
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: [Select]
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() {
 digitalWrite(10, HIGH);
 digitalWrite(11, HIGH);
 digitalWrite(12, HIGH);
 digitalWrite(10, LOW);
 digitalWrite(11, LOW);
 digitalWrite(12, LOW);
 // start the SPI library:
 // initalize the  data ready and chip select pins:
 pinMode(chipSelectPin, OUTPUT);

void loop() {

 // don't do anything until the data ready pin is Low:

     digitalWrite(chipSelectPin, HIGH);
      int tempData = SPI.transfer(A6);
   // take the chip select low to de-select:
     digitalWrite(chipSelectPin, LOW);


   // display the tempdata:

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

Go Up