cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f405 spi trouble with LSM9DS0

tylere
Associate II
Posted on November 08, 2014 at 03:50

the i-nemo forum is a little slow hopefully maybe i can get a faster answer here...

I'm trying to interface with the LSM9DS0 and I can't get any coherent information from it. when I try to read the who am I register I get 0x00, but when I read the who am I register and keep the chip select pulled down all the time I get random rubbish.

My question is if  I perhaps did my spi configuration wrong? 

RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 , ENABLE);

    SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

    SPI_InitStruct.SPI_Mode = SPI_Mode_Master;

    SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b; 

    SPI_InitStruct.SPI_CPOL = SPI_CPOL_High; 

    SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;

    SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;

    SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;

    SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;

    SPI_CalculateCRC(SPI2, DISABLE);

    SPI_Init(SPI2, &SPI_InitStruct);

   SPI_SSOutputCmd(SPI2,DISABLE);

   SPI_Cmd(SPI2, ENABLE);

my other thought was maybe my mosi isn't connecting? doest anyone know what happens when you clock in zeros to the LSM9DS0? since 0x00 is a reserved address could that be why if i spam with cs pulled low that I get a response that meas nothing?
1 REPLY 1
rh7
Associate
Posted on November 21, 2014 at 11:14

I think you need to use the second edge for clock phase. I had a lot of trouble getting the LMS9DS0 to work with an STM32F4, until I discovered that I was getting reflections on my SS line.  I slowed down the speed on the GPIO pin that I was using for SS and the problem went away.

Clocking zeroes in seems to work okay for me, but I haven't got much further than the whoami registers and reading some fairly inconsistent magnetometer values.

Hope that helps.