2017-09-02 01:41 PM
Hello:
I have been fighting with this accelerometer for a couple of months and it has now become imperative that I get it functioning.
I am using it with an STM32F405 controller. I have it set up in interrupt mode. When I get an interrupt, I read and process the X,Y,Z registers but the values are always (or almost nearly) the same: -20, -3, -6.
I have absolutely not a clue what is going on. Can anyone please help me with this? Here is the code to process the data after the interrupt. Directly below is the call to SPI read that the handler uses
uint8_t SPI_read(uint8_t address)
{ GPIO_SetPinLow(GPIOD, ACCHI_CS); address = 0x80 | address; // 0b10 - reading and clearing status while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI3, address); while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET); SPI_I2S_ReceiveData(SPI3); while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI3, 0x00); while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET); GPIO_SetPinHigh(GPIOD, ACCHI_CS); return SPI_I2S_ReceiveData(SPI3);}/* Interrupt handler for EXT1 */void EXTI1_IRQHandler(void) { volatile uint8_t x = 0, y = 0, z = 0, reg; volatile float32_t cX = 0, cY = 0, cZ = 0; volatile int8_t accVal, xF,yF,zF; if (EXTI_GetITStatus(EXTI_Line1) != RESET ) { EXTI_ClearITPendingBit(EXTI_Line1);// who dunnit?
reg = SPI_read( LIS200DL_INT1SRC ); if( reg & 0x40 ) { x = SPI_read( LIS200DL_OUT_X ); y = SPI_read( LIS200DL_OUT_Y ); z = SPI_read( LIS200DL_OUT_Z ); } if( x & 0x80 ) { //it's negative, invert result accVal = x ^ 1; accVal += 0x1; cX = (accVal * 0.780); //printf('-X acc value = %.1f\n', cX); } else { cX = (x * 0.780) * -1.0; //printf('+X acc value = %.1f\n', cX); } if( y & 0x80 ) { //invert result accVal = y ^ 1; accVal += 0x1; cY = (accVal * 0.780); //printf('+Y acc value = %.1f\n', cY); } else { cY = (y * 0.780) * -1.0; //printf('-Y acc value = %.1f\n', cY); } if( z & 0x80 ) { //invert result accVal = z ^ 1; accVal += 0x1; cZ = (accVal * 0.780); //printf('+Z acc value = %.1f\n', cZ); } else { cZ = (z * 0.780) * -1.0; //printf('-Z acc value = %.1f\n', cZ); } xF = (int8_t)cX; yF = (int8_t)cY; zF = (int8_t)cZ;if( (abs(xF) > 3) || (abs(yF) > 3) || (abs(zF) > 3) )
{ myDataX = xF; myDataY = yF; myDataZ = zF; } }}
Please advise as to where I am making a mistake. If no one on this forum can help, how can I get official ST support? This device will be used on quite a few systems and right now, it is holding the project up.]\
Roger
Solved! Go to Solution.
2017-09-06 08:40 PM
Miroslav,
All is well, updated my code and the results are good. Thanks so much for your help!