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.

SPI Peripheral not working as expected.

Part Number: CC2650

Hi,

I am trying to interface Lis2de12 mems sensor with CC2650 MCU via SPI protocol.Currently, I am just trying to read the device ID register of the sensor and have not been successful yet.

Below are the SPI_params:

SPI_Params_init(&spiParams);
spiParams.transferMode = SPI_MODE_CALLBACK;
spiParams.transferCallbackFxn = &spiCallbackFxn;
spiParams.frameFormat = SPI_POL1_PHA1;
spiParams.mode        = SPI_MASTER;
spiParams.dataSize = 8;
  

Now, according to the datasheet, each read/write spi operation must be completed in 16 clock pulses and further 8 clock pulses to be added for multiple read/write bytes.

I am using following spi transaction params for spi_transfer()

 uint8_t txBuffer=0X8FU;
 uint8_t rxBuffer;

 spiTransaction.count = 1;
 spiTransaction.txBuf = &txBuffer;
 spiTransaction.rxBuf = &rxBuffer;

Spi_transfer() works in full duplex mode and the whole transaction is getting completed in 8 clock pulses only as follows-

Ideally, the data received should be coming in further 8 clock pulses and it's value must be 0X33 (as per the datasheet).

How do I overcome this?

  • Hi Rahul,

    I am not drivers expert but you are setting spiParams.dataSize = 8. Does changing this parameter impact the behaviour?

  • Hi Joakim,

    The dataSize parameter is just there to specify the number of bits being transmitted/received simultaneously in single frame.It turns out that I had to send one dummy byte after the first byte(containing the address of the register to be read) in order to receive the actual data in 16 clock pulses.

    So I setup the transfer as follows:

    uint8_t txBuffer[2]={0X8FU,0X00U};
    uint8_t rxBuffer[2];
       
    spiTransaction.count = 2;
    spiTransaction.txBuf = &txBuffer;
    spiTransaction.rxBuf = &rxBuffer;

    With the above parameters, I was able to retreive the contents of the register in rxBuffer[1] as the transfer took 16 clock pulses as per the requirement written in datasheet.