AnsweredAssumed Answered

SPI and Timer incompatibility?

Question asked by machmallow on Jun 16, 2014
Latest reply on Jun 17, 2014 by machmallow
Hello!

I'm actually trying to use TIM2 interrupt and use SPI in the same time. But when I initialise the SPI peripheral, it doesn't work : there is no timer interrupt any more.

You can see above the main function and the useful interrupt functions

int main(void)
{
    
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
                          RCC_APB2Periph_GPIOE, ENABLE);
    


   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOA, &GPIO_InitStructure);
   GPIO_Init(GPIOB, &GPIO_InitStructure);
   GPIO_Init(GPIOC, &GPIO_InitStructure);
   GPIO_Init(GPIOD, &GPIO_InitStructure);
   GPIO_Init(GPIOE, &GPIO_InitStructure);

   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
                          RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
                          RCC_APB2Periph_GPIOE, DISABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);


    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
    GPIO_InitTypeDef gpioinit;
    gpioinit.GPIO_Mode=GPIO_Mode_IPD;
    gpioinit.GPIO_Speed=GPIO_Speed_50MHz;
    gpioinit.GPIO_Pin=GPIO_Pin_12;
    GPIO_Init(GPIOA, &gpioinit);


    if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12) != 0)
    {
        while (1)
        {
        }
    }


    /*power on RFM12 module*/ //The SPI peripheral
   RFM12_poweron();

   /*initialize SPI1 peripheral to communicate with RFM12*/
   hlperiph_SPI1master_init();
    
   /*initializes RFM12 with correct configuration*/
   RFM12_init();
   hlperiph_led_init();
   hlperiph_EXTI_PA0_init();


     uint8_t tx_start[] = "\r\nStarting main";  //Send a message throught the SPI peripheral
     RFM12_TxData(tx_start, 15);
    
 
        
      // SysTick end of count event each 1ms
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);
    


       hlperiph_timer2_init();


      // RFM12_init();
       transmit();
       RFM12_poweroff();
            
            
   /* Infinite loop */
  while (1)
  { }
}


void TIM2_IRQHandler(void)
{
    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
    {
      TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
        
        RFM12_init();
      uint8_t tx_TIM3[] = "TIM2";
      RFM12_TxData(tx_TIM3, 4);
        
    }
}


Thank you very much,

Héloïse

Outcomes