Go Down

Topic: 25LC256 issue (Read 2 times) previous topic - next topic

johnwasser

That pinout looks correct and means that Pin 10 is being used as the Slave Select (CS) pin.  You need to add pinMode(10, OUTPUT); and digitalWrite(10, HIGH); to setup() and then before each command you add digitalWrite(10, LOW); to enable the SPI device.  Add digitalWrite(10, HIGH);  after al the data for the command has been transferred.

That will get you closer and will make it clear what commands you are sending.  It will probably still not work until you issue the right commands.  It would probably help if you could put into comments what you expect each part of the code to do.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

jrlc

Oh! I see ... I think .. SPI library that it automatically  :smiley-roll-blue:

I'll try that...

jrlc

I have to change some code to make it work, but now is working :)

Thanks!  :smiley-yell:

Now I'll try to make a writing cycle, and a reading cycle.

Code: [Select]
#include <SPI.h>
int variable = 2; //data that you want to record
int resultado, registro=0; // variable to record from EEPROM, position of the registry

void setup() {
  pinMode(10,OUTPUT);
  digitalWrite(10, HIGH);
  Serial.begin(9600);
  SPI.begin(); 
  SPI.setDataMode(SPI_MODE3);  //setup SPI protocol
  SPI.setClockDivider(SPI_CLOCK_DIV2); // 10 Mhz max for 25LC256
  SPI.setBitOrder(MSBFIRST);
 
  digitalWrite(10, LOW);
  SPI.transfer(6);  //write enable 6
  digitalWrite(10, HIGH);
 
  digitalWrite(10, LOW);
  SPI.transfer(1); //remove block protection 1,0
  SPI.transfer(0);
  digitalWrite(10, HIGH);
  delay(5);
 
  for(int j=0; j<9; j++)
  {
      digitalWrite(10, LOW);
      SPI.transfer(6); //write enable 6
      digitalWrite(10, HIGH);
     
      digitalWrite(10, LOW);
      SPI.transfer(2); // write 2,0
      SPI.transfer(0);
      SPI.transfer(registro); // registry
      SPI.transfer(variable); // data
      digitalWrite(10, HIGH);
      delay(5);
     
      digitalWrite(10, LOW);
      SPI.transfer(6); // write enable 6
      digitalWrite(10, HIGH);
     
      digitalWrite(10, LOW);
      SPI.transfer(3); // read 3,0
      SPI.transfer(0);
      SPI.transfer(registro); // registry
      resultado = SPI.transfer(0x00);
      digitalWrite(10, HIGH);
       
      Serial.print("direccion");
      Serial.print(registro);
      Serial.print(" : ");
      Serial.println(resultado);
      registro++;
      variable++;
  }
  digitalWrite(10, LOW);
  SPI.transfer(4); // write disabled 4
  digitalWrite(10, HIGH);
}

void loop() {}

jrlc

This is the writting cycle:

Note: I added a led to digital pin 2 to show when the cycle is finished.

Code: [Select]
#include <SPI.h>
int variable = 56; //data to record
int resultado, registro=0;

void setup() {
 pinMode(10,OUTPUT);
 pinMode(2,OUTPUT);
 digitalWrite(10, HIGH);
 digitalWrite(2, HIGH);
 SPI.begin();  
 SPI.setDataMode(SPI_MODE3);  // set SPI protocol
 SPI.setClockDivider(SPI_CLOCK_DIV2); // 10 Mhz max for 25LC256
 SPI.setBitOrder(MSBFIRST);
 
 digitalWrite(10, LOW);
 SPI.transfer(6);  // write enable 6
 digitalWrite(10, HIGH);
 
 digitalWrite(10, LOW);
 SPI.transfer(1); // remove block protection 1,0
 SPI.transfer(0);
 digitalWrite(10, HIGH);
 delay(5);
 
 for(int j=0; j<9; j++)
 {
     digitalWrite(10, LOW);
     SPI.transfer(6); // write enabled 6
     digitalWrite(10, HIGH);
     
     digitalWrite(10, LOW);
     SPI.transfer(2); // write 2,0
     SPI.transfer(0);
     SPI.transfer(registro); // registry
     SPI.transfer(variable); // data to record
     digitalWrite(10, HIGH);
     delay(5);
     
     digitalWrite(10, LOW);
     SPI.transfer(6); // write enabled 6
     digitalWrite(10, HIGH);

     registro++;  // +1
     variable++;  // +1
 }
 digitalWrite(10, LOW);
 SPI.transfer(4); // write disabled 4
 digitalWrite(10, HIGH);
}

void loop() {
digitalWrite(2, LOW);
}


This is the reading cycle:

Note: I added a led to digital pin 2 to show when the cycle is finished.

Code: [Select]
#include <SPI.h>
int resultado, registro=0;

void setup() {
 pinMode(10,OUTPUT);
 pinMode(2,OUTPUT);
 digitalWrite(10, HIGH);
 digitalWrite(2, HIGH);
 Serial.begin(9600);
 SPI.begin();  
 SPI.setDataMode(SPI_MODE3);  //setup SPI protocol
 SPI.setClockDivider(SPI_CLOCK_DIV2); // 10 Mhz max for 25LC256
 SPI.setBitOrder(MSBFIRST);
 
 for(int j=0; j<9; j++)
 {
     digitalWrite(10, LOW);
     SPI.transfer(3); // read 3,0
     SPI.transfer(0);
     SPI.transfer(registro); // registry
     resultado = SPI.transfer(0x00);
     digitalWrite(10, HIGH);
     
     Serial.print("direccion"); //print on screen
     Serial.print(registro);
     Serial.print(" : ");
     Serial.println(resultado);
     registro++;
 }
}

void loop() {
digitalWrite(2, LOW);
}

Go Up