23k256 ram with arduino

Hi all, i’m trying to use an 23k256 ram with arduino pro mini. I’ve tryed this code:

#include <SPI.h>
 
//SRAM opcodes
#define RDSR 5
#define WRSR 1
#define READ 3
#define WRITE 2
 
uint8_t SpiRAMRead8(uint16_t address) {
  uint8_t read_byte;
 
  PORTB &= ~(1<<PORTB2); //set SPI_SS low
  SPI.transfer(READ);
  SPI.transfer((char)(address >> 8));
  SPI.transfer((char)address);
  read_byte = SPI.transfer(0xFF);
  PORTB |= (1<<PORTB2); //set SPI_SS high
  return read_byte;
}
 
void SpiRAMWrite8(uint16_t address, uint8_t data_byte) {
  PORTB &= ~(1<<PORTB2); //set SPI_SS low
  SPI.transfer(WRITE);
  SPI.transfer((char)(address >> 8));
  SPI.transfer((char)address);
  SPI.transfer(data_byte);
  PORTB |= (1<<PORTB2); //set SPI_SS high
}
 
void setup(void) {
  uint16_t addr;
  uint8_t i;
 
  Serial.begin(9600);
  SPI.begin();
  for (addr=0; addr<32; addr++) {
    SpiRAMWrite8(addr, (uint8_t)addr);
    Serial.print("Addr: ");
    Serial.print(addr);
    i = SpiRAMRead8(addr);
    Serial.print(" | Read: ");
    Serial.println((uint16_t)i);
  }
}
 
void loop() {
}

Found here:

But when i’m going to serial monitor, it display only understandable reponse at half baund speed(4800 instead of 9600) that declared ( Serial.begin(9600) ). Why?

Another thing, how I can test how fast it write on this ram?

Which one do you have?

There are two version of the Pro Mini. One runs at 3.3V and 8 MHz, the other at 5V and 16 MHz.

It sounds like you chose the wrong one from the menu.

how I can test how fast it write on this ram?

You can't. You are accessing it through SPI so crank up the SPI speed, if you find one speed that will not work chances are that is over the write speed. However SPI is slow compared to the speed of rams.
If you want to know the write speed then look in the data sheet.

But I can mesure time when code start and when it finish writing? And maybe extract average of N writes of 2bytes each.

Yaro:
But I can mesure time when code start and when it finish writing? And maybe extract average of N writes of 2bytes each.

You can but that will only tell you the time of the SPI transfer, it will tell you nothing about the write time of the RAM.

Ok, that's what i need. How can i accomplish this?

As you said, make a note of the time at the start of the code and the time at the end of the code and subtract the two.
Normally you would use the millis() timer but that is too slow for just a few bytes so transfer something like 1000 bytes and time it.

Thank you.

Also, I'm almost sure that I have arduino 5v, it's "atmega328p-AU". (I don't really remember if I bought 5v or 3v3, but i'm running it at 5v) I'm suppling ram with raw pin. I've tryed different options in Arduino Type selecting pro mini 3v3, 5v, 8mhz and 16mhz, but nothing change. I can't understand why is running at half speed.

Ok, that's what i need. How can i accomplish this?

Look at ProfileTimer HERE