Exemplo n.º 1
0
/**
 * Reset 1-wire bus (~1 ms).
 */
static inline uint8_t reset(void)
{
    uint8_t tmp = 0;
    uint8_t result = 0;

    TIM1_SetAutoreload(485);
    TIM1->CR1 |= TIM1_CR1_CEN;
    OW_PORT->ODR |= OW_OUT;
    while (TIM1->CR1 & TIM1_CR1_CEN);
    OW_PORT->ODR &= ~OW_OUT;
    TIM1_ClearFlag(TIM1_FLAG_UPDATE);

    // Wait once again, sample within 100 mks
    TIM1->CR1 |= TIM1_CR1_CEN;
    while (TIM1->CR1 & TIM1_CR1_CEN)
    {
        tmp = TIM1->CNTRH;
        if (TIM1->CNTRL >= RESET_TIME)
            break;
    }
    result = (OW_PORT->IDR & OW_IN) == 0;

    // Wait for the end of reset period.
    while (TIM1->CR1 & TIM1_CR1_CEN);
    TIM1_ClearFlag(TIM1_FLAG_UPDATE);

    TIM1_SetAutoreload(60);
    return result;
}
Exemplo n.º 2
0
/**
  * @brief  Configure TIM1 peripheral
  * @param  None
  * @retval None
  */
static void TIM1_Config(void)
{
  /* configure TIM1 channel 1 as PWM Output */
  TIM1_OC1Init(TIM1_OCMode_PWM1, TIM1_OutputState_Enable, TIM1_OutputNState_Disable,
               0x7FF/* TIM1_Pulse */, TIM1_OCPolarity_Low, TIM1_OCNPolarity_Low,
               TIM1_OCIdleState_Reset, TIM1_OCNIdleState_Reset);

  /* Set TIM1 Autoreload value*/
  TIM1_SetAutoreload(0xFFF);

  /* Enable TIM1 */
  TIM1_Cmd(ENABLE);

  /* GPIO configuration: TIM1 channel 1 (PD2)*/
  GPIO_Init(GPIOD, GPIO_Pin_2 , GPIO_Mode_Out_PP_Low_Fast);

  /* Enable TIM1 Outputs*/
  TIM1_CtrlPWMOutputs(ENABLE);  
}