Microchip 23K256/Arduino Transfer Rates

Saleae Logic

I used my Saleae Logic to time the transfer (read/write) rates between the Arduino and Microchip 23k256 SPI SRAM. See this post for more information on the Arduino and 23K256.

Here is the program that was running on the Arduino:

#include <SPI.h>

//SRAM opcodes
#define RDSR        5
#define WRSR        1
#define READ        3
#define WRITE       2
//SRAM Hold line override
#define HOLD        1
//SRAM modes
#define BYTE_MODE   (0x00 | HOLD)
#define PAGE_MODE   (0x80 | HOLD)
#define STREAM_MODE (0x40 | HOLD)

//Byte transfer functions
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) {
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);
}

void loop() {
  uint16_t i;
  uint8_t value;

  for (i=0; i<32; i++) {
    SpiRAMWrite8((i*i), (uint8_t)i);
    value = SpiRAMRead8((i*i));
  }
  delay(10);
}

Per the following screen capture, you can see the entire transfer from Arduino to SRAM took 6.46µs (for the period the CS line is held low). You can also see the data going out on the MOSI line: READ command (b00000010 or 2) followed by the 2-byte address and then the data byte (in this example, b00000001 or 1). Notice the MISO line is low during the entire transfer and you can see the clock pulses on the SCK line. The clock period is 0.125µs or 8MHz. The fastest speed the ATMega168 SPI can operate at is the oscillator rate divided in half (16/2 = 8MHz).

SRAM Write Operation

The following screen capture shows the entire transfer from SRAM to Arduino took 6.5µs (again for the period the CS pin is held low).

SRAM Read Operation

Advertisements

About Jim Eli

µC experimenter
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s