Problem with limited memory space

@iquita2005, I’m not 100% certain that SPI1.begin(SPI_MODE_MASTER, D5); will set pin D5 as an output. You may want to add a pinMode(D5, OUTPUT); prior to the SPI` settings. As for the validity of your command sequence, I’ll need to read the datasheets before I can comment on that.

I’m sorry, I shared an incorrect PIN connection. This is the correct one.

@iquita2005, can you explain this sequence:

    SPI1.transfer(0x01);
    SPI1.transfer(mode << 6);

You are writing 0x01 << 6 or 0x40 to the mode register. I can’t find any such command in the datasheet. You might want test by first only reading the Mode register. However, I noticed that you don’t quite fully understand the way data is clocked in and out of the device. This is the sequence you should follow:

  1. Clock the command byte to the device. The SPI bus will put out eight SCK pulses to clock the data from the MOSI pin to the SI pin of the device. To read the Mode register, the command would be issued using:
    SPI1.transfer(0x05)

  2. Clock a dummy byte out the the device (typically 0x00) to allow the device to supply the actual register value being read. Doing this causes the SPI bus to put out eight SCK pulses to clock in the data from the device SO pin into the MISO pin. So to read the actual register value being returned, your code will work with minor modification:
    int readBuff = SPI1.transfer(0x00);

Also, the pull-up resistor is not necessary on the HOLD# pin as it can be tied to Vdd directly.

Hello
We implemented your recommendation, but this did not help.

    // SRAM SPI
    pinMode (D5, OUTPUT);   // Set D5 as output
    SPI1.setClockSpeed(1, MHZ); // Reduced speed just in case
    SPI1.setBitOrder(MSBFIRST);
    SPI1.setDataMode(SPI_MODE0);  
    SPI1.begin(SPI_MODE_MASTER, D5);

// Read Mode reguster (RDMR)
    uint8_t writeBuff[2];
    uint8_t readBuff[3];

    writeBuff[0] = 0x05;
    writeBuff[1] = 0x00;
    clearBuf(readBuff, 3);  // Fill buffer with 0x00 

      digitalWrite(D5, LOW);
      SPI1.transfer(writeBuff, readBuff, 2, spiFinish);
      WaitForSPIFinished(); // The function waiting for 12us
      digitalWrite(D5, HIGH);

After that code both bytes in readBuffer are 0xFF. But it should be 0x40 value (default mode according chip datasheet)
Just for test, I changed SPI_MODE from 0 to 1,2,3. And for each one I had the same result 0xFF.

Also the same result for two single byte SPI1.transfer commad

 readBuff[0] = SPI1.transfer(0x05);
 readBuff[1] = SPI1.transfer(0x00);

I thought that this is a hardware issue.

When your 0x05 0x00 is the read command, it needs to be transferred in it’s entirety before you can read back the data that command is meant to produce.
You need to write two bytes first and then read the two result bytes - four bytes or 32 clock cycles in total.

BTW, what is your spiFinish() callback actively doing. If you only want to wait for the transfer to finish, you can provide NULL instead of a callback function - that makes the call synchronous.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.