cancel
Showing results for 
Search instead for 
Did you mean: 

LIS302DL MEMS: How to use INT1 and INT2 outputs

jean
Senior
Posted on August 06, 2014 at 16:06

Hello everybody !

I try to use the LIS302 (the mems accelerometer of the discovery board).

On the datasheet, I don't understand what are the outputs INT1 and INT2, what are the differences?

Thanks for your time :)

#spi-mems #mems #spi-mems #spi-mems
9 REPLIES 9
jpeacock2399
Associate II
Posted on August 06, 2014 at 16:50

One use for dual interrupts is to assign INT1 for regular application processing, when an axis is updated.  INT2 can be used for either a wakeup (any axis change over a certain amount wakes up controller from sleep mode), or it can be used as a high priority interrupt when a fall condition (high acceleration on Z axis) is detected.  Since you may be in the middle of a regular update from INT1 when a fall occurs there isn't time to restart a data transfer.  An INT2 event tells you a fall is in progress without having to poll the chip registers, so you can react quickly, for instance parking heads on a disk drive to minimize damage.

  Jack Peacock

jean
Senior
Posted on August 06, 2014 at 18:07

Thanks a lot for your answer Jack! Now it seems obvious for me.

I have another question. I try to read the registers of the LIS302 but the receipted byte is always 0xFF (for every registers). 

I'm not sure that my LIS302DL is well soldered on my custom board (I can't check, because the pins of this MEMS are under the IC). Is it possible to receive the 0xFF byte even if the LIS302 is not well mounted? I use SPI.

Thanks !
jpeacock2399
Associate II
Posted on August 07, 2014 at 00:32

Check the polarity of your clock output to make sure your reads and writes are on the proper edge of the clock.  This assumes you are also generating a clock output, it isn't automatic.  No data is almost always a missing clock or polarity problem, assuming the peripheral has been initialized and is selected.

  Jack Peacock
jean
Senior
Posted on August 07, 2014 at 10:06

Thanks Jack! I know that I'm generating the right clock because I can see it on the scope. And I use the same SPI to control a screen wich is working (of course I use CS pins to select and deselect the corresponding ICs).

How to know if my LIS302 is well initialized?

Thanks!
jean
Senior
Posted on August 07, 2014 at 10:13

I don't know if someone already succeeded in soldering this component with a soldering iron :)

jpeacock2399
Associate II
Posted on August 07, 2014 at 16:01

Read the WHO_AM_I register and make sure you see 0x3b as the response.  If not you may have either SPI hardware problems (do you read and write on rising edge, do you send a TX clock when reading?) or your software driver isn't working.

  Jack Peacock

jean
Senior
Posted on August 07, 2014 at 18:15

When I read theWHO_AM_I register I see a 0xFF response... With my scope I can see that send the clock.

I know that my SPI works because I can communicate with my screen controller on the same SPI2. And this SPI have the same config parameters as the SPI1 on the discovery board coded by ST. So I think there is no problems about the SPI config. About the MEMS accelerometer driver, I use the one provided by ST for the discovery board, I just changed SPI1 to SPI2. And I always have 0xFF when I read...

void
SPI2_Config(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
// Alternate Functions connection
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
// CLOCK and MOSI and MISO Pins declaration
GPIO_InitStructure.GPIO_Pin = PIN_SCL | PIN_SI | PIN_SDO; 
// PB13, PB14 and PB15 for SPI2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Init SPI 2____________________
SPI_InitTypeDef SPI_InitStruct;
SPI_I2S_DeInit(SPI2);
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_Low; 
SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge; 
SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; 
SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; 
SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStruct);
SPI_Cmd(SPI2, ENABLE);
}

void
Accelerometer_Config(
void
)
{
uint8_t ctrl = 0;
uint32_t idelay = 0;
//SysTick_Config(SystemCoreClock/ 100);
/* Set configuration of LIS302DL*/
LIS302DL_InitTypeDef LIS302DL_InitStruct;
LIS302DL_InitStruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
LIS302DL_InitStruct.Output_DataRate = LIS302DL_DATARATE_100;
LIS302DL_InitStruct.Axes_Enable = LIS302DL_X_ENABLE | LIS302DL_Y_ENABLE | LIS302DL_Z_ENABLE;
LIS302DL_InitStruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
LIS302DL_InitStruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
LIS302DL_Init(&LIS302DL_InitStruct);
/* Set configuration of Internal High Pass Filter of LIS302DL*/
LIS302DL_InterruptConfigTypeDef LIS302DL_InterruptStruct;
LIS302DL_InterruptStruct.Latch_Request = LIS302DL_INTERRUPTREQUEST_LATCHED;
LIS302DL_InterruptStruct.SingleClick_Axes = LIS302DL_CLICKINTERRUPT_Z_ENABLE;
LIS302DL_InterruptStruct.DoubleClick_Axes = LIS302DL_DOUBLECLICKINTERRUPT_Z_ENABLE;
LIS302DL_InterruptConfig(&LIS302DL_InterruptStruct);
/* Required delay for the MEMS Accelerometre */
for
(idelay = 0; idelay < 5000000; idelay++){}
/* Configure Interrupt control register: enable Click interrupt1 */
ctrl = 0x07;
LIS302DL_Write(&ctrl, LIS302DL_CTRL_REG3_ADDR, 1);
/* Enable Interrupt generation on click/double click on Z axis */
ctrl = 0x70;
LIS302DL_Write(&ctrl, LIS302DL_CLICK_CFG_REG_ADDR, 1);
/* Configure Click Threshold on X/Y axis (10 x 0.5g) */
ctrl = 0xAA;
LIS302DL_Write(&ctrl, LIS302DL_CLICK_THSY_X_REG_ADDR, 1);
/* Configure Click Threshold on Z axis (10 x 0.5g) */
ctrl = 0x0A;
LIS302DL_Write(&ctrl, LIS302DL_CLICK_THSZ_REG_ADDR, 1);
/* Configure Time Limit */
ctrl = 0x03;
LIS302DL_Write(&ctrl, LIS302DL_CLICK_TIMELIMIT_REG_ADDR, 1);
/* Configure Latency */
ctrl = 0x7F;
LIS302DL_Write(&ctrl, LIS302DL_CLICK_LATENCY_REG_ADDR, 1);
/* Configure Click Window */
ctrl = 0x7F;
LIS302DL_Write(&ctrl, LIS302DL_CLICK_WINDOW_REG_ADDR, 1);
/* Read CLICK_CFG register */
LIS302DL_Read(&ctrl, LIS302DL_WHO_AM_I_ADDR, 1); 
// After this read, ctrl always equal 0xFF
}

jpeacock2399
Associate II
Posted on August 08, 2014 at 21:08

<< I know that my SPI works because I can communicate with my screen controller on the same SPI2. And this SPI have the same config parameters as the SPI1 on the discovery board coded by ST. So I think there is no problems about the SPI config. >>

No it doesn't tell you the SPI bus is working for the LIS302.  First, the screen controller may use a different clock polarity for read/write.  If you read on the wrong clock edge you may not get any data from the LIS302.  

Polarity is critical for SPI, and not all SPI peripherals use the same edges, so don't assume that if it works for one IC it will work for another.  There is no real standard for this.

Second, it doesn't tell you if you have a connection to the IC.  Do you see data being clocked on the MISO pin, from the LIS302 back to the STM32?  Do you know if the other device on your SPI bus is tri-stated when you do the read, or is it forcing the shared MISO pin hi?  Look at the clock and MISO pins on a scope, first to see if any data is being sent and second on what edge is the data valid.

It's very possible you don't have a good connection to the IC, in which case you see no data on the MISO pin during a read.

  Jack Peacock
jean
Senior
Posted on August 11, 2014 at 10:18

Hi Jack,

Thanks. I think I use the good polarity because I use the SPI config from the ST firmware example for the LIS302. My screen use luckily the same SPI config parameters.

The fact is I can scope the right clock, MOSI and CS signals. But I have nothing in return on the MISO pin, so maybe I have a bad connection.

I try everything to solder the LIS302 with my soldering iron, but it change nothing. This MEMS package (LGA14) is just horrible for prototyping! Please ST, never use this package again...