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.

CC2640R2F: SPI receive the same data every time (it's the register who_am_i)

Part Number: CC2640R2F

Hi!

I'm using the LaunchPad CC2642R1/CC2652R1 with the accelerometer LIS2DH and i tested the "who am i" (0x33) register to validate the protocol but when i tried read another register i had the same response that "who am i"  (0x33) register. Could you help me with this problem or give me some ideas to solve it?

//transmitBuffer
transmitBuffer[0] = ((0x80) | WHO_AM_I_ACELEROMETER);
transmitBuffer[1] = (0x00);
//receiveBuffer
receiveBuffer[0] = (0x00);
receiveBuffer[1] = (0x00);
//transaction
spiTransaction.count = 2;
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;
transferOK = SPI_transfer(spi, &spiTransaction);
if (!transferOK) {
// Error in SPI or transfer already in progress.
while(1);
}

//transmitBuffer
transmitBuffer[0] = ((0x00) | CTRL_REG1); //Write
transmitBuffer[1] = (0x97);
//receiveBuffer
receiveBuffer[0] = (0x00);
receiveBuffer[1] = (0x00);
//transaction
spiTransaction.count = 2;
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;
transferOK = SPI_transfer(spi, &spiTransaction);
if (!transferOK) {
while(1);
}

transmitBuffer[0] = ((0x80) | CTRL_REG4);
transmitBuffer[1] = (0x00); 
//receiveBuffer
receiveBuffer[0] = (0x00);
receiveBuffer[1] = (0x00);
//transaction
spiTransaction.count = 2;
spiTransaction.txBuf = (void *)transmitBuffer;
spiTransaction.rxBuf = (void *)receiveBuffer;
transferOK = SPI_transfer(spi, &spiTransaction);
if (!transferOK) {
while(1);
}

Thank you in advance.

Best regards,

Tania

  • Hi Tania,

    What SPI parameters are you using?  Please reference the spimaster example and SPI TI Driver reference. The transferMode should be SPI_MODE_BLOCKING based on the code you've provided thus far.  I highly recommend using a logic analyzer or oscilloscope to monitor your SPI lines.  What is received if registers other than WHO_AM_I are read first?  Try switching the order to view its effect, and/or evaluate the addition of a delay between SPI reads.

    Regards,
    Ryan

  • Hi Ryan,

    I'm using this parameters:

    SPI_Params_init(&spiParams); // Initialize SPI parameters
    spiParams.transferMode = SPI_MODE_BLOCKING;
    spiParams.mode = SPI_MASTER;
    spiParams.bitRate = 400000;
    spiParams.dataSize = 8;
    spiParams.frameFormat = SPI_POL0_PHA0;

    and for each register the receive is who am i register (0x33).

    Best regards,

    Tania

  • The LIS2DH datasheet SPI slave timing diagram suggests a SPI_POL1_PHA1 format, which is why visually recording and observing the SPI communication could effectively debug this interface.  Have you interacted with this accelerometer before using a different master device, or do you have any online examples to reference?

    Regards,
    Ryan

  • When I used the other options of "POL and PHA" I got no response only on "SPI_POL0_PHA0" so I used that one. This is my first time with this accelerometer and SPI in CCS.

    I'm using the SPI driver of CCS and datasheets of microcontroller and accelerometer.

  • Have you tried changing the order of registers read to determine whether you can ever receive something other than 0x33?  It may be a coincidence that this value matches the WHO_AM_I register.  You should also verify your hardware connections to ensure that the VCC, GND, MOSI, MISO, CLK, and CS pins are all connected properly.  It will not be possible to further assist with debugging a third-party sensor without SPI line monitoring.

    Regards,
    Ryan

  • I'm using the STEVAL-MKI135V1 board with just the next connections:

    • MOSI to SDA
    • MISO to SDO
    • CLK to CLK
    • CS to "Low" "0"
    • ADC1, ADC2 and ADC3 to GND
    • VDD to 3.3V
    • VDD_IO to 3.3V

    I got the following response when I was trying to read the CTRL_REG1 in first place (it's the same case with others register).

    Step 1: Read "CTRL_REG1"

    It only receives 0x33 from the "who am i" register when it is the first register read but when I try another register later the register "who am i" the following responses were obtained:

    Step 1: Read "WHO_AM_I"

    Step 2: Read "CTRL_REG1"

  • Hi Tania,

    I think what you are seeing after writing the CTRL_REG1 register is normal. If you read the accelerometer x, y, z and you still see 0x33, then there is a problem. Try also communicating with I2C and see if you are getting the same results.

    Another issue with ST accelerometer chip is the availability to buy in mass quantities. 

    -kel

  • You can contact STMicroelectronics for further support regarding their LIS2DH device and STEVAL-MKI135V1 adapter board.  They will likely ask you for logic analyzer or oscilloscope screenshots of the SPI communication lines as well.  You may consider controlling the CS pin through software to determine whether this is expected operation from the LIS2DH.

    Regards,
    Ryan

  • Hi Ryan,

    Thank you for your help.

    Regards,

    Tania