Commit 3d801568 authored by Alain Monney's avatar Alain Monney Committed by Anne Donnet
Browse files

IC for us corrected

parent af859c2e
......@@ -506,15 +506,20 @@ void HCSR04_Read (TIM_HandleTypeDef* htim, uint32_t* sensors_data)
{
sensors_data[N_IR_SENSORS+N_US_SENSORS-1] = 60000;
}
__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_IT_CC1, TIM_INPUTCHANNELPOLARITY_RISING);
HAL_TIM_IC_Stop_IT(htim, TIM_CHANNEL_2);
HAL_TIM_IC_Start_IT(htim, TIM_CHANNEL_1);
HAL_GPIO_WritePin(US_trigger1_GPIO_Port, US_trigger1_Pin, GPIO_PIN_RESET); // pull the TRIG pin low
delay_us(2);
HAL_GPIO_WritePin(US_trigger1_GPIO_Port, US_trigger1_Pin, GPIO_PIN_SET); // pull the TRIG pin HIGH
delay_us(10); // wait for 10 us
HAL_GPIO_WritePin(US_trigger1_GPIO_Port, US_trigger1_Pin, GPIO_PIN_RESET); // pull the TRIG pin low
__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_IT_CC1, TIM_INPUTCHANNELPOLARITY_RISING);
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
// htim->State = HAL_TIM_STATE_READY;
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
// __HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_IT_CC1, TIM_INPUTCHANNELPOLARITY_RISING);
// __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
//// htim->State = HAL_TIM_STATE_READY;
// __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
US_value_captured[0] = 0;
i++;
break;
......@@ -523,15 +528,20 @@ void HCSR04_Read (TIM_HandleTypeDef* htim, uint32_t* sensors_data)
{
sensors_data[N_IR_SENSORS+i-1] = 60000;
}
__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_IT_CC2, TIM_INPUTCHANNELPOLARITY_RISING);
HAL_TIM_IC_Stop_IT(htim, TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(htim, TIM_CHANNEL_2);
HAL_GPIO_WritePin(US_trigger2_GPIO_Port, US_trigger2_Pin, GPIO_PIN_RESET); // pull the TRIG pin low
delay_us(2);
HAL_GPIO_WritePin(US_trigger2_GPIO_Port, US_trigger2_Pin, GPIO_PIN_SET); // pull the TRIG pin HIGH
delay_us(10); // wait for 10 us
HAL_GPIO_WritePin(US_trigger2_GPIO_Port, US_trigger2_Pin, GPIO_PIN_RESET); // pull the TRIG pin low
__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_IT_CC2, TIM_INPUTCHANNELPOLARITY_RISING);
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
// htim->State = HAL_TIM_STATE_READY;
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
// __HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_IT_CC2, TIM_INPUTCHANNELPOLARITY_RISING);
// __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
//// htim->State = HAL_TIM_STATE_READY;
// __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
US_value_captured[1]=0;
i=0;
break;
......
......@@ -160,9 +160,9 @@ int main(void)
HAL_TIM_Base_Start_IT(&htim9);
HAL_TIM_Base_Start_IT(&htim12);
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_4);
// HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1);
// HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_2);
// HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_4);
HAL_UART_Receive_DMA(&huart2, &UART_rx_byte, sizeof(UART_rx_byte));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment