2016-09-23 03:07 AM
Hi to all i have this problem, i have a STM32L152RE with a temperature Sensor,
this sensor use 1-wire protocol,the data is codifing with pulse width, lather the mcu start the connection the sensor give the 40 bit, i have 0 if the pulse width is 28 usec, i have 1 if the pulse is 70 usec. I use cube_mx for configure the board, i use the time3, channel 2 with interrupt, this is the my configuration /* TIM3 init function */ static void MX_TIM3_Init(void) { TIM_ClockConfigTypeDef sClockSourceConfig; TIM_MasterConfigTypeDef sMasterConfig; TIM_IC_InitTypeDef sConfigIC; htim3.Instance = TIM3; htim3.Init.Prescaler = 32000; //1MHz htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 65535; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; if (HAL_TIM_Base_Init(&htim3) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_IC_Init(&htim3) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING; sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; sConfigIC.ICFilter = 15; // input filter if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) { Error_Handler(); } now all work well, but where should I set the width codifing?: void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) { int i=0; uint32_t input_capture; if (htim->Instance==TIM3) { input_capture=__HAL_TIM_GetCompare(&htim3, TIM_CHANNEL_2); //READ TIM3 channel 2 printf ( '' Value: %u \n \r '' , input_capture); // debug ... } can you help me? best regards antonio #one-wire #input_capture2016-09-23 03:31 AM
Hi AntonioB,
You put the signal's width calculation inside the HAL_TIM_IC_CaptureCallback() function. I recommend to follow the ready-to-use example ''TIM_InputCapture'' in the STM32CubeL1 at this path: STM32Cube_FW_L1_V1.6.0\Projects\STM32L152D_EVAL\Examples\TIM\TIM_InputCapture -Hannibal-