1

I am using several 23LC1024 SRAM chips to share data between an Arduino and a Raspberry PI 3 running Windows 10 IOT. I am using SPI to send and read data from the 23LC1024. I am having trouble getting the data to write and read back correctly. I am using a Logic Analyzer to check my commands at formatted correctly. I am using the SPI0 from the PI. I am using this 23LC1024 Data sheet (http://ww1.microchip.com/downloads/en/DeviceDoc/20005142C.pdf) and Application notes for 23LC1024 (http://ww1.microchip.com/downloads/en/AppNotes/01484A.pdf). I am using figure 1 as an example for my schematic, with 4.7kOhm resistors, and 100nF Capacitor. I have the chip set to read/write 32 bit pages.

Here is a capture of my write command to address 0 and 0xAA as my data. [Write 0xAA to address 0]
Here is a capture of my read command to address 0. [SPI command to read data at address 0 followed by read]
The return data is all 0's.

I am using SPI Mode 0 (CPOL = 0, CPHA = 0), with a clock speed of 100000. Here is how I define my constants used by the PI.

static class SRAMConsts
{
    //SRAM Instruction
    public const Byte RDMR =    0x5;
    public const Byte WRMR =    0x1;
    public const Byte WRITE =   0x2;
    public const Byte READ =    0x3;
    //SRAM Modes
    public const Byte BYTE_MODE =       0x00;
    public const Byte PAGE_MODE =       0x80;
    public const Byte SEQUENTIAL_MODE = 0x40;
    //SRAM Page size
    public const Byte PAGE_SIZE = 0x20;
    //SRAM Max Speed
    public const int Spi_Max_Speed = 0x1312d00;  // 20MHz
    //SRAM Spi Mode
    public const SpiMode Mode0 = SpiMode.Mode0;
}

Here is my code to read and write a page to the SRAM.

public void readPage(UInt32 address, ref byte[] data)
{
    byte[] cmd = new byte[4];
    byte[] result = new byte[32];
    cmd[0] = SRAMConsts.READ;
    cmd[1] = (byte)(address >> 16);
    cmd[2] = (byte)(address >> 8);
    cmd[3] = (byte)(address);
    GPIO_CS.Write(GpioPinValue.High);
    _23LC1024_Sram.Write(cmd);
    _23LC1024_Sram.Read(result);
    GPIO_CS.Write(GpioPinValue.Low);
    data = result;
}

public void writePage(UInt32 address, ref byte[] data)
{
    byte[] cmd = new byte[4];
    cmd[0] = SRAMConsts.WRITE;
    cmd[1] = (byte)(address >> 16);
    cmd[2] = (byte)(address >> 8);
    cmd[3] = (byte)(address);
    GPIO_CS.Write(GpioPinValue.High);
    _23LC1024_Sram.Write(cmd);
    _23LC1024_Sram.Write(data);
    GPIO_CS.Write(GpioPinValue.Low);
}

I am able to successfully read and write to the chips from an Arduino, but still can not get the PI to read and write correctly. I am hoping this setup will allow the PI to share a common address space with the Arduino so that the Arduino can be used to produce data.

Any ideas as to why my PI is not communication properly with the SRAM chip.

5
  • 1
    Can you see any differences in waveforms from Arduino and RPi? Commented Aug 31, 2017 at 7:55
  • @DmitryGrigoryev I do see that the PI drives the CS high between the command and the data write.
    – spudtracktoad
    Commented Sep 1, 2017 at 1:03
  • 1
    @DmitryGrigoryev After looking a the way the Arduino communicates with the chip and how the Pi does I found that the PI pulls the CS line High after each SPI.Write this causes the chip to switch state and wait for the next command instead of clocking in the data. I solved the problem by using a GPIO pin as the CS.
    – spudtracktoad
    Commented Sep 1, 2017 at 1:48
  • @Put that as an answer (perhaps with a couple of diagrams) and ping me in comments. I'll be happy to upvote! Commented Sep 1, 2017 at 10:13
  • @DmitryGrigoryev I put an answer up thanks for the help
    – spudtracktoad
    Commented Sep 3, 2017 at 1:57

1 Answer 1

2

After closely comparing the SPI signals between the Arduino and the PI I noticed that the PI pulled the chip select pin high after each write in my 'writePage' function. This function calls SPI.Write two time which is why the CS pin is pulled high. Because I had a logic error in my GPIO values in the function my manual CS pin was not actually being utilized to select the chip. With some changes I could use the SPI.TransferSequential command, which I may try in the future.

Here is a capture of the Arduino Write Arduino Write

Here is a capture of the Arduino Read Arduino Read

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.