1
\$\begingroup\$

I'm using a CC2652r to try to read and write to an MX25R8035F EEPROM using SPI.

I'm using the build in SPI driver to try and communicate with the EEPROM but while the drivers says it succeeded the transfer of data, the data I get back seems to be 0 at all times.

For example if I try to use the REMS (read electronic manufacturer & device ID) to get the manufacturer & device ID I send 4 bytes containing 0x90, 0xFF, 0xFF, 0x00. But instead of getting 0xC2, 0x14. I'm getting 0x00 and 0x00.

I initialize my SPI with:

    /* Open SPI as master (default) */
    SPI_Params_init(&spiParams);
    spiParams.dataSize = 8;
    spiParams.bitRate = SPI_BIT_RATE; //(4000000)
    spiParams.frameFormat = SPI_POL0_PHA0;
    masterSpi = SPI_open(MX25_EEPROM_SPI, &spiParams);
    if (masterSpi == NULL) {
        System_abort("Error initializing SPI\n");
    }

Then in a Task I try to get the electronic manufacturer & device ID with:

//BLS_CODE_MDID = 0x90
    uint8_t wbuf[] = { BLS_CODE_MDID, 0xFF, 0xFF, 0x00 };
    SPI_Transaction transaction;

    // Configure the transaction
    transaction.count = sizeof(wbuf);
    transaction.txBuf = wbuf;
    transaction.rxBuf = NULL;
    extFlashSelect();
    uint8_t ret = (uint8_t) (!SPI_transfer(masterSpi, &transaction));

    // Configure the transaction
    transaction.count = sizeof(infoBuf);
    transaction.txBuf = NULL;
    transaction.rxBuf = infoBuf;

    ret = (uint8_t) (!SPI_transfer(masterSpi, &transaction));
    extFlashDeselect();

Where extFlashSelect put the slave select pin low and extFlashDeselect put it to high.

I also tried setting the rxBuf and the txBuf in the same transaction but got the same result.

I hope someone is able to help me with this.

EDIT:
I tried specifying the frame format in the parameters passed to SPI_open.
According to the documentation of MX25R8035F, CPOL 0, CPHA 0 and CPOL 1, CPHA 1 together should be supported but the result is still the same.

\$\endgroup\$
9
  • 3
    \$\begingroup\$ if you have a scope, this is a good time to use it. \$\endgroup\$
    – user16324
    Feb 18, 2020 at 16:10
  • 1
    \$\begingroup\$ Most SPI problems are due to the polarity and phase of the clock (there are 4 variants for SPI, known as modes). I will also note that SPI has no way to know if an error occurred in data transfer (think of it as a circular shift register). You need to show the clock polarity and phase being used. \$\endgroup\$ Feb 18, 2020 at 16:32
  • 1
    \$\begingroup\$ @PeterSmith I edited the question to show the polarity. I tried both supported pol and phase options but those gave the same result sadly. \$\endgroup\$ Feb 19, 2020 at 8:47
  • 2
    \$\begingroup\$ Just to ask all the "obvious" questions- can you confirm that /CS is connected and toggling prior to the read attempt, and that the MOSI/MISO are connected properly to SI/SO respectively? \$\endgroup\$ Feb 19, 2020 at 9:09
  • 1
    \$\begingroup\$ @SpehroPefhany I connected an LED to the CS to check if it toggled and it did as it was supposed to (turn off on select and turn back on on deselect). I just checked the continuity between the MISO and SO and the MOSI and SI and both seemed connected. \$\endgroup\$ Feb 19, 2020 at 9:24

1 Answer 1

1
\$\begingroup\$

So I tried some more stuff. Eventually I tried to read the REMS using an arduino that worked after sending a dummy byte while trying to retrieve data.

I now tried the same with the TI board and it returned data.

Updated function for retrieving the REMS is now:

    //BLS_CODE_MDID = 0x90
    uint8_t wbuf[] = { BLS_CODE_MDID, 0xFF, 0xFF, 0x00 };

    SPI_Transaction transaction;
    uint8_t dummy[] = { 0 };
    uint8_t infoBuf[2];

    // Configure the transaction
    transaction.count = sizeof(wbuf);
    transaction.txBuf = wbuf;
    transaction.rxBuf = NULL;

    extFlashSelect();

    if (!SPI_transfer(masterSpi, &transaction)) {
        return 1;
    }

    // Configure the transaction
    transaction.count = sizeof(infoBuf);
    transaction.txBuf = dummy;
    transaction.rxBuf = infoBuf;

    uint8_t ret = (uint8_t) (!SPI_transfer(masterSpi, &transaction));
    extFlashDeselect();
\$\endgroup\$
1
  • \$\begingroup\$ Regardless if this seems to have solved the problem, listen to the guy who did RTFM in comments above and told you about clock phase. Set it accordingly. If you set SPI clock phase wrong you get a communication link that works most of the time, then suddenly breaks down during some condition (supply or temperature drifting or whatever), then starting to clock in wrong data etc. en.wikipedia.org/wiki/Clock_skew \$\endgroup\$
    – Lundin
    Mar 4, 2020 at 14:12

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.