2018-02-26 07:11 PM
When I use this function __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) like this:
__HAL_TIM_SET_COMPARE(&htim3,TIM_CHANNEL_2,10);
//I should use the '&' with the handle para.
what will happen if I use it like
__HAL_TIM_SET_COMPARE(htim3,TIM_CHANNEL_2,10) without '&'?
But when I use IWDG funtion __HAL_IWDG_RELOAD_COUNTER(__HANDLE__):
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
//why no '&' here?
#stm32f0-hal #__handle__ #stm322018-02-26 08:03 PM
You want to pass it as an address, so typically it would have and &
You're second case is where it is already an address (pointer) like inside
HAL_IWDG_Init().
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
{...
/* Reload IWDG counter with value defined in the reload register */
__HAL_IWDG_RELOAD_COUNTER(hiwdg);..
}
vs top level stuff
static IWDG_HandleTypeDef IwdgHandle; // ACTUAL PHYSICAL STRUCTURE
..
/*##-3- Configure & Start the IWDG peripheral #########################################*/
/* Set counter reload value to obtain 1 sec. IWDG TimeOut. IWDG counter clock Frequency = uwLsiFreq Set Prescaler to 32 (IWDG_PRESCALER_32) Timeout Period = (Reload Counter Value * 32) / uwLsiFreq So Set Reload Counter Value = (1 * uwLsiFreq) / 32 */ IwdgHandle.Instance = IWDG; IwdgHandle.Init.Prescaler = IWDG_PRESCALER_32; IwdgHandle.Init.Reload = (uwLsiFreq / 32); IwdgHandle.Init.Window = IWDG_WINDOW_DISABLE;if(HAL_IWDG_Init(&IwdgHandle) != HAL_OK) // ADDRESS OF STRUCTURE
{ /* Initialization Error */ Error_Handler(); }This would seem to be basic C pointer stuff.