Author Topic: RAM 23k256  (Read 1670 times)

0 Members and 1 Guest are viewing this topic.

Offline lorenrusTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: it
RAM 23k256
« on: April 12, 2020, 04:37:55 pm »
Code: [Select]

#include <SPI.h>

//SRAM Status Register opcodes
#define BYTE_MODE B00000000                    // 0     dec
#define PAGE_MODE B10000000                    // 128   dec
#define SEQUENTIAL_MODE B01000000              // 64    dec

//SRAM Status Register opcodes disabling HOLD pin
#define BYTE_MODE_NO_HW_HOLD B00000001         // 1     dec
#define PAGE_MODE_NO_HW_HOLD B10000001         // 129   dec
#define SEQUENTIAL_MODE_NO_HW_HOLD B01000001   // 65    dec

//SRAM opcodes
#define READ_STATUS_REGISTER B00000101         // 5     dec
#define WRITE_STATUS_REGISTER B00000001        // 1     dec
#define READ B00000011                         // 3     dec
#define WRITE B00000010                        // 2     dec

#define ZERO ((uint8_t) 0x00)                  // 0     dec
#define MAX_VALUE ((uint8_t) 0xFF)             // 255   dec
#define MAX_ADDR ((uint16_t) 0x7FFF)           // 32767 dec
#define MAX_PAGE ((uint8_t) 0x0400)            // 1024  dec
#define MAX_WORD_PER_PAGE ((uint8_t) 0x20)     // 32    dec

#define SET_SS_LOW() (PORTB &= ~(1<<PORTB2)) //set SPI_SS low
#define SET_SS_HIGH() (PORTB |= (1<<PORTB2)) //set SPI_SS high

uint8_t SpiRAMReadStatusRegister() {
  uint8_t read_status;
 
  //SET_SS_LOW();
  digitalWrite(53, LOW);
  SPI.transfer(READ_STATUS_REGISTER);
  read_status = SPI.transfer(0xFF);
  //SET_SS_HIGH();
  digitalWrite(53, HIGH);
 
  return read_status;
}


void SpiRAMWriteStatusRegister(uint8_t command) {

  digitalWrite(53, LOW);
  //SET_SS_LOW();
  SPI.transfer(WRITE_STATUS_REGISTER);
  SPI.transfer(command);
  //SET_SS_HIGH();
  digitalWrite(53, HIGH);
 
}

byte SpiRAMReadByte(uint16_t address) {

  Serial.println("*********** FASE DI LETTURA ***************");
 
  byte read_byte;

  digitalWrite(53, LOW);
 
  SPI.transfer(READ);
  SPI.transfer((char) (address >> 8));
  SPI.transfer((char) address);
  read_byte = SPI.transfer(0xFF);

  Serial.print("INDIRIZZO DI LETTURA = ");
  Serial.println(address, DEC);

  delay(200);
 
  Serial.print("VALORE LETTO = ");
  Serial.println(read_byte, DEC);
 
  digitalWrite(53, HIGH);

 
 
  return read_byte;
}



void SpiRAMWriteByte(uint16_t address, byte data_byte) {

  Serial.println("*********** FASE DI SCRITTURA ***************");
 
  digitalWrite(53, LOW);
 
  SPI.transfer(WRITE);
  SPI.transfer((char) (address >> 8));
  SPI.transfer((char) address);
  SPI.transfer(data_byte);

  Serial.print("INDIRIZZO DI SCRITTURA = ");
  Serial.println(address, DEC);

  delay(200);
 
  Serial.print("DATO SCRITTO = ");
  Serial.println(data_byte, DEC);
 
  digitalWrite(53, HIGH);
}

byte x = 1;

void setup() {
 
  Serial.begin(9600);
  SPI.begin();

  pinMode(53, OUTPUT); // pin CS
 
  SpiRAMWriteStatusRegister(BYTE_MODE);
 
  if(SpiRAMReadStatusRegister() != BYTE_MODE) {
    Serial.println("Errory while setting status register (byte operative mode)!");
  }
  else {
    Serial.println("Byte operative mode correctly set!");
  }
 
}




void loop() {
 
  SpiRAMWriteByte(0, x);

  delay(2000);
 
  if(SpiRAMReadByte(0) <= 10) {

    delay(8000);
   
    x = x + 1;

  }
  else {

    Serial.println("FINITO");
  }


 
  //delay(10);


Hello everyone and good Easter

I wanted to ask you a question about RAM memory 23k256.

I wrote the code I entered.
I wrote it that way because I wanted to check if I could overwrite the value of a fixed RAM lease and then increase it until I had interest, obviously increasing it to a maximum number that can be expressed with 8 bits. I say this last thing because I use writing and reading a byte.

What I ask you is because in images 1 and 2 attached I get those results circled in red.

Until the writing of the fourth value all ok then I write the value 5 but I read the value 6, then I write the value 9 but read the 10, and here should have appeared the finished inscription, instead it appears when I write the 10 and read the 12.

Can you help me?

Thank you.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4750
  • Country: nr
  • It's important to try new things..
Re: RAM 23k256
« Reply #1 on: April 12, 2020, 05:44:08 pm »
You are missing "}" at the end of loop()..

Also try with following:

Code: [Select]


..
for (byte x=0; x<=10; x++) {
  SpiRAMWriteByte(0, x);
  SpiRAMReadByte(0);
  }

Serial.println("FINITO");

} // end of setup()


void loop() {
}
« Last Edit: April 12, 2020, 06:09:27 pm by imo »
 
The following users thanked this post: lorenrus

Offline lorenrusTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: it
Re: RAM 23k256
« Reply #2 on: April 12, 2020, 06:02:21 pm »
AH ok. When i paste the code in the message I forgot the last parenthesis, but of course that is not the problem since the images show that the program has been compiled and executed. In any case thanks :)
 

Offline lorenrusTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: it
Re: RAM 23k256
« Reply #3 on: April 12, 2020, 06:29:55 pm »
About your code:

I need to compare the value in memory through the use of the IF.
So I need to put SpiRAMReadByte(0) in the IF argument.

Thank you
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: RAM 23k256
« Reply #4 on: April 15, 2020, 12:40:26 am »
I see youve commented out a bunch of the Slave Select commands. How is SS being handled?

Many SPI devices require SS to start and end transactions which could effect a write, or allow a new address to be sent for a new read/write. Many devices also implement sequential reads/writes, where subsequent reads/writes just work on the next memory address, so if SS is not released then you probably wont see what you are looking for.

But it does kind of seem to be working as is.

Show a schematic and maybe a picture of your setup, perhaps there are signal integrity issues as well.
 
The following users thanked this post: lorenrus

Offline lorenrusTopic starter

  • Regular Contributor
  • *
  • Posts: 64
  • Country: it
Re: RAM 23k256
« Reply #5 on: April 18, 2020, 08:03:07 pm »
Hi

comand SS is digitalWrite(53, LOW/HIGH);

if I write writes with separate commands, always overwriting the same address as RAM memory, it works correctly. Instead, if I do this by iterating the memory index variable, it gives me the problem that I'm reporting n the first message.

I was thinking about some synchronization/timing issues between reading and writing on the SPI. What do you think? Thank you
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: RAM 23k256
« Reply #6 on: April 19, 2020, 06:40:00 am »
Maybe. According to its datasheet, the SRAM chip seems to use fairly typical SPI operation (usually called mode 0) which is: input data latched on the rising edge of SCK, output data changes on the falling edge of SCK.

Presumably just calling SPI.Begin() without any settings configures the SPI peripheral like this? Arduino docs werent clear about this from a quick glance. I would normally explicitly specify all settings so there is no ambiguity.

Do you have an oscilloscope and can look at your signals to make sure they are clean, no excessive ringing, no slow edges etc?

Maybe its just too plain to see, but I dont really see anything wrong with the code itself. Where did you get your chips and do you have another one to test with? Perhaps it is faulty.
 
The following users thanked this post: lorenrus

Offline ale500

  • Frequent Contributor
  • **
  • Posts: 415
Re: RAM 23k256
« Reply #7 on: April 19, 2020, 07:17:03 am »
In the circuit you have shown, there is a 100 pF (pico Farad) capacitor to VCC, you may want to increment the value to say 100 nF (nano Farad) :).

I normally go like this (I like SPI Displays and they are always a surprise regarding timing!).

Electrical:

The clock is output on the desired pin. Test with the multimeter for continuity and shorts. Test toggling the pin.

go on with the other pins.


A pullup/pull down on the clock may help.

SW:

Do the transfer using pure SW, no SPI HW !!! Then you know it works.

Change to HW SPI. Be sure that you select the chip before the rise of the clock and that you de-select the chip AFTER the last clock... sometimes the SPI flags indicate "buffer empty", so it can send a new byte, but it doesn't mean that the transmission is actually finished !.





 
The following users thanked this post: lorenrus


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf