Skip to main content
Visitor II
December 21, 2022
Solved

Inclinometer Murata SCL3300, wrong results if I read more angles

  • December 21, 2022
  • 2 replies
  • 3485 views

Hi, I solve a problem with reading more parameters from the inclinometer Murata SCL3300. The communication works without errors, the init state is OK and when I read more parameters, I get the wrong results.

For SPI communication I use HAL_SPI_TransmitReceive(&hspi2, tx_data, rx_data, 1, 100); I attached my code.

Does anyone have the same problem?

    This topic has been closed for replies.
    Best answer by toman

    The problem was in reading data. Responses are shifted as shown in the datasheet. The data reading code should look like this:

    // first command
     transfer(RdAngX);
      if (crcerr || statuserr) errorflag = true;
     
    // second command 
    	 transfer(RdAngY);
    	 if (crcerr || statuserr) errorflag = true;
     
    // response to the first command 
    	 angleX = (SCL3300_DATA / 16384.) * 90.;
     
    // third command 
    	 transfer(RdAngZ);
    	 if (crcerr || statuserr) errorflag = true;
     
    // response to the second command 
    	 angleY = (SCL3300_DATA / 16384.) * 90.; 
     
    	 transfer(RdStatSum);
    	 if (crcerr || statuserr) errorflag = true;
    	 angleZ = (SCL3300_DATA / 16384.) * 90.; 
     
    	 transfer(Read_WHOAMI);
    	 if (crcerr || statuserr) errorflag = true;

    2 replies

    ST Employee
    December 22, 2022

    Hi @toman​ ,

    which MCU are you using?

    Since the inclinometer is manufactured by Murata, I suggest you to post your question on their online support page, to get a direct help --> LINK.

    -Eleon

    tomanAuthor
    Visitor II
    December 27, 2022

    Hi @Eleon BORLINI​ ,

    thanks for your answer and suggestion. I try to add this question on the Murata support page. I use a basic processor STMF103C8T6. 

    I think the problem will be in using the function HAL_SPI_TransmitReceive. The protocol needs to send 4 bytes and receive 4 bytes (see screens from the datasheet). In my case, I use this code:

    for (int i = 3; i >= 0; i--) {

    tx_data[0] = dataorig.bit8[i];

    status = HAL_SPI_TransmitReceive(&hspi2, tx_data, rx_data, 1, 100);

    dataorig.bit8[i] = rx_data[0];

    The first parameter read OK (for example TiltX), but the second is invalid (e.g. TiltY). I think, there is a collision in the data flow. Is there any description of the function HAL_SPI_TransmitReceive?

    0693W00000Y6vtaQAB.png0693W00000Y6vtzQAB.pngThank you. Tomas

    tomanAuthorAnswer
    Visitor II
    January 5, 2023

    The problem was in reading data. Responses are shifted as shown in the datasheet. The data reading code should look like this:

    // first command
     transfer(RdAngX);
      if (crcerr || statuserr) errorflag = true;
     
    // second command 
    	 transfer(RdAngY);
    	 if (crcerr || statuserr) errorflag = true;
     
    // response to the first command 
    	 angleX = (SCL3300_DATA / 16384.) * 90.;
     
    // third command 
    	 transfer(RdAngZ);
    	 if (crcerr || statuserr) errorflag = true;
     
    // response to the second command 
    	 angleY = (SCL3300_DATA / 16384.) * 90.; 
     
    	 transfer(RdStatSum);
    	 if (crcerr || statuserr) errorflag = true;
    	 angleZ = (SCL3300_DATA / 16384.) * 90.; 
     
    	 transfer(Read_WHOAMI);
    	 if (crcerr || statuserr) errorflag = true;

    ST Employee
    January 5, 2023

    Hi @toman​ ,

    I'm glad you solved the issue and reported it!

    -Eleon