cancel
Showing results for 
Search instead for 
Did you mean: 

I use the LIS3MDL Sensor: When I power the sensor and request via SPI the WHOAMI Register, the first answer is not equal to the default answer. When I send another byte to read the Register afterwards I get the default answer. Why is that so?

LLoid.1
Associate

 data[0]=0B10001111;

 data[1]=0B00000000;

data[3]=0B00000000; //this is not needed but i get the default answer here

   SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE3));

   digitalWrite(10, LOW);

   delay(10);

   for (size_t i = 0; i < datalen; i++)

   {

       data[i] = SPI.transfer(data[i]);

   }

   digitalWrite(10, HIGH);

   SPI.endTransaction();

2 REPLIES 2
S.Ma
Principal

a littke empathy here. what chip is spi master?

remember spi receives a byte wheb one is sent. of course the first received correspond to the subaddress being sent. if the spi has hw fifo, it will be saved for you to read first.not all stm32 for example have spi fifos....

LLoid.1
Associate

sorry for littke emphathy, was not my intention. Thank you for your quick response.

My SPI Master is the ATMEGA 328 on Arduino Nano.

The Problem with the response via SPI ist, that the second answer (data[1]) from the Sensor is not the expected answer.

I think it might be a Sensor specific problem. When I try this code via the Arduino IDE and try to read the register in a loop i get the expected answer. But with c++ with a single request to the register i dont get the expected answer.