2022-12-21 04:40 AM
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?
Solved! Go to Solution.
2023-01-04 11:37 PM
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;
2022-12-22 05:35 AM
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
2022-12-27 07:26 AM
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?
Thank you. Tomas
2023-01-04 11:37 PM
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;
2023-01-05 01:24 AM
Hi @toman ,
I'm glad you solved the issue and reported it!
-Eleon