This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: MSP432P401R SPI Read Problem

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I am communicating with NCV7708F chip using MSP432P401R uC via SPI. I need to verify my each write operation by reading every write. NCV7708F has standard 16 bit spi communication implementation. The problem is NCV7708F read and write operations are simultaneous.

When I send 00 or FF to provide clock for read operation. Previously written bytes are received but it also over writes 00 or FF to chip.

My Code for read and write:

    /*! Select Device. */
    NCV7708F_BSP_spi_sel_dev();

    /*! Send Byte 0. */
    rx_byte_0 = NCV7708F_BSP_spi_write_and_read_byte(tx_byte0);

    /*! Send Byte 1. */
    rx_byte_1 = NCV7708F_BSP_spi_write_and_read_byte(tx_byte1);

    /*! Send 00 to provide clock for read operation. */

    /*! For Byte 0. */
    rx_byte_2 = NCV7708F_BSP_spi_write_and_read_byte(0x00); // tx_byte0 received

    /*! For Byte 1. */
    rx_byte_3 = NCV7708F_BSP_spi_write_and_read_byte(0x00); // tx_byte1 received

    /*! Un-select Device. */
    NCV7708F_BSP_spi_desel_dev();

static inline uint8_t NCV7708F_BSP_spi_write_and_read_byte(const uint8_t byte) {

    /*! Transmit characters. */
    EUSCI_B0->TXBUF = byte;

    /*! Wait till a character is received (this wait is necessary). */
    while (!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG)) ;


    /*! Return received character. */
    return EUSCI_B0->RXBUF;
}

 Can someone please guide me how can i perform read operation without over writing data. Thank you.

  • I had a bit of trouble reading the datasheet description of SRR, but it sounds like if you send SRR=0 you can send anything and it won't "stick". But that conflicts with your observation about using 0x00 as a dummy byte.

    You may need to keep an in-memory image of what (you believe) is in the chip, and send that for dummy bytes. (I've done worse things.)

  • Hi Hassan,

    Looks like you tried to attach couple of images to your message but they did not come through.

    In addition to Bruce's suggestion the data sheet for NCV7708F also says this - "The SI data will be accepted when a valid SPI frame is detected. A valid SPI frame consists of the above conditions and a complete set of multiples of 16 bit words. Invalid frames are ignored with previous input data intact" (pg. 9 in the section on SPI communication). Is it possible to send/write a dummy invalid frame while performing the read. This should ensure that the data on NCV7708F is not overwritten?

    Srinivas

  • Hi Bruce,

    thank you for your reply. SRR = 0 means no reset but it has nothing to do with write protection.

  • Hi Sirinivas,

    Thank you for your reply.

    I tried creating invalid frames for read operation but so far unsuccessful.

    Approach 1:
    After write operation I made CSB high while sending dummy bytes for read. I received FF because SO was in tristate.

    Approach 2:

    I tried all 4 combinations of clock polarity and phase (CKPL, CKPH) to find an invalid frame. But SPI communication with chip NCV7708F is same and correct with all 4 combinations.

  • Hi Srinivas,

    Yeah my images attachment was unsuccessful I have attached them again: 

  • It looks like you're reading back what you wrote. That tells us that (a) the SPI settings are probably correct (b) it updates the control register immediately. There's also a suggestion that the control register is 0000 at reset -- not too surprising, but I didn't find that in the data sheet.

    If you read two bytes then (immediately) write those two bytes (rxbyte_0/1) back (maybe with SRR=1?), I expect it will restore the original settings. Since doing that has potential for glitches, I suggest you only do this at startup, and (as suggested above) save away rx_byte_0/1 as a mirror of what's in the device.

    Then, when you want to change something, modify your mirror copy and write that to the device.

**Attention** This is a public forum