/**
* @brief  Read the status register.
* @param  None
* @retval Status
*/
void Spirit1InterfaceInit(void)
{ 
  /* Initialize the SDN pin micro side */
  RadioGpioInit(RADIO_GPIO_SDN,RADIO_MODE_GPIO_OUT);

  SpiritSpiInit();
  
#if defined(SPIRIT1_HAS_EEPROM)
  EepromSpiInitialization();
#endif
     
  /* Board management */   
  SpiritEnterShutdown(); 
  SpiritExitShutdown();   
    
  SpiritManagementIdentificationRFBoard();
    
  /* Initialize the signals to drive the range extender application board */
  SpiritManagementRangeExtInit(); 
  
  /* Micro EXTI config */   
  RadioGpioInit(RADIO_GPIO_IRQ,RADIO_MODE_EXTI_IN);
  RadioGpioInterruptCmd(RADIO_GPIO_IRQ,0x04,0x04,DISABLE); 
  RadioGpioInterruptCmd(RADIO_GPIO_IRQ,0x04,0x04,ENABLE);
}
Example #2
0
void SPIRIT_INIT(void)
{
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);   // Use STM32L1xx_flash.icf
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE );
  SdkEvalIdentification();
  SdkStartSysTick();
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
  SdkEvalLedInit(LED1);
  SdkEvalLedInit(LED2);
  SdkEvalM2SGpioInit(M2S_GPIO_SDN,M2S_MODE_GPIO_OUT);
  SpiritSpiInit();  
  USART1_Init();
  
  SpiritEnterShutdown();
  SpiritExitShutdown();
  
  SpiritManagementIdentificationRFBoard();
  SdkEvalM2SGpioInit(M2S_GPIO_0, M2S_MODE_EXTI_IN);
  
  SdkEvalM2SGpioInterruptCmd(M2S_GPIO_0,0x0F,0x0F,ENABLE);
  SpiritGpioInit(&xGpioIRQ);
  SpiritRadioInit(&xRadioInit);
  SpiritPktBasicInit(&xBasicInit);
  SpiritPktBasicAddressesInit(&xAddressInit);
  SpiritIrqDeInit(&xIrqStatus);
   SpiritIrq(RX_DATA_DISC, S_ENABLE);
   SpiritIrq(RX_DATA_READY, S_ENABLE);  // testy dla odbioru komend !!!!!
  SpiritIrq(TX_DATA_SENT, S_ENABLE);
  SpiritIrq(TX_FIFO_ERROR, S_ENABLE);
  
  // Declare Length of Payload
  SpiritPktBasicSetPayloadLength(PAYLOAD_LENGTH);
  
  SpiritQiSetSqiThreshold(SQI_TH_0);
  SpiritQiSqiCheck(S_ENABLE); 
  SpiritIrqClearStatus();
  
 // SET_INFINITE_RX_TIMEOUT();
  SpiritTimerSetRxTimeoutMs(RX_TIMEOUT);
  //SpiritTimerSetRxTimeoutStopCondition(TIMEOUT_ALWAYS_STOPPED);
  SpiritTimerSetRxTimeoutStopCondition(SQI_ABOVE_THRESHOLD);
  
  SpiritIrqClearStatus();
  //USART_Conf();
  
  //*** For test purposes only: create unsigned, 16-bit counter
  vectcTxBuff[0] = 0;   // Clear Counter to overwrite initial values
  vectcTxBuff[1] = 0;
  SdkDelayMs(2000);  //wait till the tested board FW active
 // IWDG_Init();      // let the dogs out,
}
Example #3
0
/**
 * @brief  System main function.
 * @param  None
 * @retval None
 */
void main (void)
{
     
  //*** DiZiC SPIRIT1 Demo
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);   // Use STM32L1xx_flash.icf
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE );
  SdkEvalIdentification();
  SdkStartSysTick();
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
  SdkEvalLedInit(LED1);
  SdkEvalLedInit(LED2);
  SdkEvalM2SGpioInit(M2S_GPIO_SDN,M2S_MODE_GPIO_OUT);
  SpiritSpiInit();
  WUKPIN1_Init();
  /*********************/

  /* Allow access to RTC Domain */
//   PWR_RTCAccessCmd(ENABLE);

  /* Clear WakeUp flag */
//  PWR_ClearFlag(PWR_FLAG_WU);

  /* Check if the StandBy flag is set */
//  if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
//  {
    /* Clear StandBy flag */
//    PWR_ClearFlag(PWR_FLAG_SB);

    /* Wait for RTC APB registers synchronisation */
//    RTC_WaitForSynchro();
    /* No need to configure the RTC as the RTC config(clock source, enable,
       prescaler,...) are kept after wake-up from STANDBY */
 

//  }
  
   
 
    /* RTC Configuration */
  
    /* Reset RTC Domain */
//    RCC_RTCResetCmd(ENABLE);
//    RCC_RTCResetCmd(DISABLE);

    /* Enable the LSE OSC */
//     RCC_LSICmd(ENABLE);
    
    /* Wait till LSE is ready */
//    while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
//    {}

    /* Select the RTC Clock Source */
//    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

    /* Enable the RTC Clock */
//    RCC_RTCCLKCmd(ENABLE);


    /* Wait for RTC APB registers synchronisation */
//    RTC_WaitForSynchro();
    
 
   /* RTC domain*/  
//  RTC_WakeUpCmd(DISABLE);
  
//  RTC_ITConfig(RTC_IT_WUT , ENABLE);
//  RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div4); 
//  RTC_SetWakeUpCounter(0xFF00);
  
//  PWR_WakeUpPinCmd(PWR_WakeUpPin_1 , DISABLE);
  
  
  
#ifdef USE_VCOM
  /* VC config */
 // SdkEvalVCInit();
 // while(bDeviceState != CONFIGURED);
#endif

  /* Spirit ON */
  SpiritEnterShutdown();
  SpiritExitShutdown();
  
  
  SpiritManagementIdentificationRFBoard();
  SdkEvalM2SGpioInit(M2S_GPIO_0,M2S_MODE_EXTI_IN);
  
  /* Spirit IRQ config */
  SpiritGpioInit(&xGpioIRQ);
  SdkEvalM2SGpioInterruptCmd(M2S_GPIO_0,0x0F,0x0F,ENABLE);
  
  //*** SdkEvalLedOn(LED1);
  /* Spirit Radio config */
  SpiritRadioInit(&xRadioInit);
  
  /* Spirit Packet config */
  SpiritPktBasicInit(&xBasicInit);
  SpiritPktBasicAddressesInit(&xAddressInit);

  /* Spirit IRQs enable */
  SpiritIrqDeInit(&xIrqStatus);
  SpiritIrq(RX_DATA_DISC,S_ENABLE);
  SpiritIrq(RX_DATA_READY,S_ENABLE);
  SpiritIrq(TX_DATA_SENT , S_ENABLE);

  

  /* payload length config */
  SpiritPktBasicSetPayloadLength(512);

  /* enable SQI check */
  SpiritQiSetSqiThreshold(SQI_TH_0);
  SpiritQiSqiCheck(S_ENABLE);

  /* RX timeout config */
  SpiritTimerSetRxTimeoutMs(200.0);
  SpiritTimerSetRxTimeoutStopCondition(SQI_ABOVE_THRESHOLD);

  /* IRQ registers blanking */
  SpiritIrqClearStatus();

  /* RX command */
  SpiritCmdStrobeRx();
  
  
  
 // PWR_PVDCmd(DISABLE);
 // RCC_MSIRangeConfig(RCC_MSIRange_0);
 // RCC_AdjustMSICalibrationValue(0x00);
 // RCC_MSICmd(DISABLE);
 // RCC_HSICmd(DISABLE);
//  PWR_EnterSTOPMode(PWR_Regulator_LowPower , PWR_STOPEntry_WFI);
//  PWR_UltraLowPowerCmd(ENABLE);
//  PWR_FastWakeUpCmd(ENABLE);  
 
////////////////////////////////////////////////////////////////////////////////
// 	ErrorStatus HSE_Status;
//	RCC_HSEConfig(RCC_HSE_ON);
//	HSE_Status = RCC_WaitForHSEStartUp();
//	FLASH_SetLatency(FLASH_Latency_1);
//	FLASH_PrefetchBufferCmd(ENABLE);
//	RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
//	RCC_HCLKConfig(RCC_SYSCLK_Div1);
//	RCC_PLLConfig(RCC_PLLSource_HSE, RCC_PLLMul_12, RCC_PLLDiv_3);
//	RCC_PCLK1Config(RCC_HCLK_Div1);
//	RCC_PCLK2Config(RCC_HCLK_Div1);
 ///////////////////////////////////////////////////////////////////////////////// 
  
  
  /* infinite loop */
  while (1){
    
 printf("123");
    SpiritCmdStrobeRx();
        
   
   if(PressButtom)
    {
      PressButtom = FALSE;
      
      NOPdelay(2000);
    
     // fit the TX FIFO 
      SpiritCmdStrobeFlushTxFifo();
      SpiritSpiWriteLinearFifo(500, vectcTxBuff2);
    
     // send the TX command 
     SpiritCmdStrobeTx();
    
    // wait for TX done 
     SdkEvalLedToggle(LED_GREEN);
     while(!xTxDoneFlag);
     SdkEvalLedToggle(LED_GREEN);
     xTxDoneFlag = RESET; 
     
          // fit the TX FIFO 
      SpiritCmdStrobeFlushTxFifo();
      SpiritSpiWriteLinearFifo(500, vectcTxBuff2);
    
     // send the TX command 
     SpiritCmdStrobeTx();
    
    // wait for TX done 
     SdkEvalLedToggle(LED_GREEN);
     while(!xTxDoneFlag);
     SdkEvalLedToggle(LED_GREEN);
     xTxDoneFlag = RESET; 
     
          // fit the TX FIFO 
      SpiritCmdStrobeFlushTxFifo();
      SpiritSpiWriteLinearFifo(500, vectcTxBuff2);
    
     // send the TX command 
     SpiritCmdStrobeTx();
    
    // wait for TX done 
     SdkEvalLedToggle(LED_GREEN);
     while(!xTxDoneFlag);
     SdkEvalLedToggle(LED_GREEN);
     xTxDoneFlag = RESET; 
     
     
    }
   
      
    
  }

}
Example #4
0
/*---------------------------------------------------------------------------*/
static int
spirit_radio_init(void)
{  
  PRINTF("RADIO INIT IN\n");

  SpiritSpiInit();
  
  /* Configure radio shut-down (SDN) pin and activate radio */
  SdkEvalM2SGpioInit(M2S_GPIO_SDN, M2S_MODE_GPIO_OUT);
  
  /* Configures the SPIRIT1 library */
  SpiritRadioSetXtalFrequency(XTAL_FREQUENCY);
  SpiritManagementSetVersion(SPIRIT1_VERSION);
  SpiritGeneralSetSpiritVersion(SPIRIT1_VERSION);
  SpiritManagementSetXtalFrequency(XTAL_FREQUENCY);
  
  /* wake up to READY state */
  /* weirdly enough, this *should* actually *set* the pin, not clear it! The pins is declared as GPIO_pin13 == 0x2000 */
  M2S_GPIO_SDN_PORT->BSRRL = M2S_GPIO_SDN_PIN;
/*  GPIOC->BSRRL = M2S_GPIO_SDN_PIN;*/
  GPIO_ResetBits(M2S_GPIO_SDN_PORT, M2S_GPIO_SDN_PIN);

  /* wait minimum 1.5 ms to allow SPIRIT1 a proper boot-up sequence */
  BUSYWAIT_UNTIL(0, 3 * RTIMER_SECOND/2000);
  
  /* Soft reset of core */
  spirit1_strobe(SPIRIT1_STROBE_SRES);
/*  SpiritCmdStrobeSres();*/
  
  /* Configures the SPIRIT1 radio part */
  SRadioInit xRadioInit = {
    XTAL_FREQUENCY,
    XTAL_OFFSET_PPM,
    BASE_FREQUENCY,
    CHANNEL_SPACE,
    CHANNEL_NUMBER,
    MODULATION_SELECT,
    DATARATE,
    FREQ_DEVIATION,
    BANDWIDTH
  };
  SpiritRadioInit(&xRadioInit);
  SpiritRadioSetPALeveldBm(0,POWER_DBM);
  SpiritRadioSetPALevelMaxIndex(0);
  
  /* Configures the SPIRIT1 packet handler part*/
  PktBasicInit xBasicInit = {
    PREAMBLE_LENGTH,
    SYNC_LENGTH,
    SYNC_WORD,
    LENGTH_TYPE,
    LENGTH_WIDTH,
    CRC_MODE,
    CONTROL_LENGTH,
    EN_ADDRESS,
    EN_FEC,
    EN_WHITENING
  };
  SpiritPktBasicInit(&xBasicInit);
  
  /* Enable the following interrupt sources, routed to GPIO */
  SpiritIrqDeInit(NULL);
  SpiritIrqClearStatus();
  SpiritIrq(TX_DATA_SENT, S_ENABLE);
  SpiritIrq(RX_DATA_READY,S_ENABLE);
  SpiritIrq(VALID_SYNC,S_ENABLE);
  SpiritIrq(RX_DATA_DISC, S_ENABLE);
  SpiritIrq(TX_FIFO_ERROR, S_ENABLE);
  SpiritIrq(RX_FIFO_ERROR, S_ENABLE);

  /* Configure Spirit1 */
  SpiritRadioPersistenRx(S_ENABLE);
  SpiritQiSetSqiThreshold(SQI_TH_0);
  SpiritQiSqiCheck(S_ENABLE);
  SpiritQiSetRssiThresholddBm(CCA_THRESHOLD);
  SpiritTimerSetRxTimeoutStopCondition(SQI_ABOVE_THRESHOLD);
  SET_INFINITE_RX_TIMEOUT();
  SpiritRadioAFCFreezeOnSync(S_ENABLE);
  
  /* Puts the SPIRIT1 in STANDBY mode (125us -> rx/tx) */
  spirit1_strobe(SPIRIT1_STROBE_STANDBY);
/*  SpiritCmdStrobeCommand(SPIRIT1_STROBE_STANDBY);*/
/*  SpiritCmdStrobeStandby();*/
  spirit_on = OFF;
  CLEAR_RXBUF();
  CLEAR_TXBUF();
  
  /* Initializes the mcu pin as input, used for IRQ */
  SdkEvalM2SGpioInit(M2S_GPIO_0, M2S_MODE_EXTI_IN);
  SdkEvalM2SGpioInit(M2S_GPIO_1, M2S_MODE_EXTI_IN);
  SdkEvalM2SGpioInit(M2S_GPIO_2, M2S_MODE_EXTI_IN);
  SdkEvalM2SGpioInit(M2S_GPIO_3, M2S_MODE_EXTI_IN);
  
  /* Configure the radio to route the IRQ signal to its GPIO 3 */
  SpiritGpioInit(&(SGpioInit){SPIRIT_GPIO_3, SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_LP, SPIRIT_GPIO_DIG_OUT_IRQ});

  process_start(&spirit_radio_process, NULL);

  PRINTF("Spirit1 init done\n");

  return 0;
}