cancel
Showing results for 
Search instead for 
Did you mean: 

strange interrupt's behaviour

karoui
Associate II
Posted on May 01, 2013 at 12:37

hi,

i want to generate an interrupt when i get a specified value from MEMS acceleromter :

when I reach this value sound starts and when I'm below it the sound stops but the interruption behaves contrary to what I want:

When i am  above the specified value the sound stops and it's playing if i'm below it!!!!

this is my code 

int main(void)

{

  uint8_t ctrl = 0;

   //etat = 0;

  LIS302DL_InitTypeDef  LIS302DL_InitStruct;

  //LIS302DL_InterruptConfigTypeDef LIS302DL_InterruptStruct;  

  

  /* SysTick end of count event each 10ms */

  SysTick_Config(SystemCoreClock/ 100);

  

  /* Set configuration of LIS302DL*/

  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_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: Turn-on time = 3/Output data Rate 

                                                             = 3/100 = 30ms */

  Delay(30);

  

  /* 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);

  

  /* TIM configuration -------------------------------------------------------*/

  TIM_Config(); 

  LIS302DL_Read(Buffer, LIS302DL_OUT_X_ADDR, 6);

                  

  XOffset = Buffer[0];

  YOffset = Buffer[2];

   EXTILine1_Config();  

  while(1)

  {

   

    if (Buffer[4]>=70)

    {

  /* Generate software interrupt: simulate a rising edge applied on EXTI0 line */

  EXTI_GenerateSWInterrupt(EXTI_Line1);

    }

     //EVAL_AUDIO_Stop(CODEC_PDWN_HW);

  }

}

void EXTILine1_Config(void)

{

  

  

  NVIC_InitTypeDef   NVIC_InitStructure;

  /* Enable SYSCFG clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  

 

  /* Connect EXTI Line0 to PA0 pin */

  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);

  /* Configure EXTI Line0 */

  EXTI_InitStructure.EXTI_Line = EXTI_Line1;

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_InitStructure);

   /* Enable and set EXTI Line0 Interrupt to the lowest priority */

  NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}

void EXTI1_IRQHandler(void)

{

  if(EXTI_GetITStatus(EXTI_Line1) != RESET)

  {

       WavePlayBack(I2S_AudioFreq_48k);

    /* Clear the EXTI line 0 pending bit */

    EXTI_ClearITPendingBit(EXTI_Line1);

  }

}

void WavePlayBack(uint32_t AudioFreq)

{

&sharpif defined MEDIA_IntFLASH 

  

  /* Initialize wave player (Codec, DMA, I2C) */

  WavePlayerInit(AudioFreq);

  

  /* Play on */

  AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS),AUDIO_FILE_SZE,AUIDO_START_ADDRESS);

}

Thanks in avance 

#volatile-main-loop
1 REPLY 1
dthedens23
Associate II
Posted on May 01, 2013 at 17:16

I would not call the function to play the wave file from the ISR.

have the ISR set a flag variable (remember the keyword volatile)

then have the main loop test/clear the flag and call the function.

There is no main loop!!!