2023-01-23 05:59 PM
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?
How can i set up the accelerometer? I can't read any register other than who am i (this register is shows in each reading).
Thank you in advance.
Best regards,
Tania
Solved! Go to Solution.
2023-01-25 10:12 AM
> CS to "Low" "0"
Hard wired low? Think (don't have your hardware) you need to toggle it for each new SPI transfer. Otherwise you end up in the "Multiple bytes SPI read protocol", see Figure 8 of the data sheet. And, since MS bit is not set, you are reading the same reg over and over again.
hth
KnarfB
2023-01-24 12:00 AM
Welcome, @TVela.1, to the community!
First of all, I would like to point out that with the LIS2DH you are working with a sensor that is already on NRND (Not Recommended for New Designs) and therefore should not be used for new developments.
Maybe the Github repository will help you, where you can still find generic C drivers as well as some examples for the LIS2DH?
Regards
/Peter
2023-01-24 03:31 AM
Where is your code?
hth
KnarfB
2023-01-24 08:05 AM
Hi KnarfB,
This is my code:
//Register
#define WHO_AM_I_ACELEROMETER (0x0F)
#define WHO_AM_I_R (0x33)
#define Read (0x80)
#define Write (0x00)
#define CTRL_REG1 (0x20)
********************************************************************
SPI_Params_init(&spiParams); // Initialize SPI parameters
spiParams.transferMode = SPI_MODE_BLOCKING;
spiParams.mode = SPI_MASTER;
spiParams.bitRate = 100000;
spiParams.dataSize = 8;
spiParams.frameFormat = SPI_POL0_PHA0;
spi = SPI_open(CONFIG_SPI, &spiParams);
if (spi == NULL) {
while (1); // SPI_open() failed
}
//transmitBuffer
transmitBuffer[0] = ((Read) | 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);
}
//======================Validation of address================================
if(receiveBuffer[1] == WHO_AM_I_R){
//transmitBuffer
transmitBuffer[0] = (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);
}
//========Read register CTRL_REG1=========
//transmitBuffer
transmitBuffer[0] = (CTRL_REG1 | (Read));
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);
}
}
Best regards,
Tania
2023-01-24 08:59 AM
Is CS asserted as shown in the data sheet?
In the above debug window, transmitBuffer[0] shows 0xA3 which is different from what I would expect from the code?
Hook up a cheap logic analyzer and watch the waveforms if you can.
hth
KnarfB
2023-01-24 09:38 AM
Yes, i'm using cs as "0" and 0xA3 is the register that i'm reading (0x23) with the bit to read (0x80, this is part of the protocol).
My issue is with receiveBuffer. I'm receiving the same data every time "who am i" register.
Regards,
Tania
2023-01-24 03:28 PM
I'm using the STEVAL-MKI135V1 board with just the next connections:
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"
2023-01-25 09:53 AM
I understand, could you confirm if the connection is correct? I'm using another IDE.
2023-01-25 10:12 AM
> CS to "Low" "0"
Hard wired low? Think (don't have your hardware) you need to toggle it for each new SPI transfer. Otherwise you end up in the "Multiple bytes SPI read protocol", see Figure 8 of the data sheet. And, since MS bit is not set, you are reading the same reg over and over again.
hth
KnarfB
2023-02-10 10:41 AM
Hi KnarfB,
Sorry for the delay. Toggle it was the solution.
Thank you for your help.