2024年1月15日发(作者:)
------------------------------------------------------------------------------------------------------------------------------------------------------STM32库函数TIM_CCxCmd()和TIM_CCxNCmd()错误
Hefei Fulaide Electronics Science&technology Co., Ltd.
2015年9月7日,在使用PWM时,调试发现STM32 V3.5的库有几个函数有问题。下载了STM32 V3.61的库,也是同样的问题,于是自己修改这个BUG。
STM32库函数TIM_CCxCmd()和TIM_CCxNCmd()错误修改:
/**
* @brief Enables or disables the TIM Capture Compare Channel x.
* @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral.
* @param TIM_Channel: specifies the TIM Channel
* This parameter can be one of the following values:
* @arg TIM_Channel_1: TIM Channel 1
* @arg TIM_Channel_2: TIM Channel 2
* @arg TIM_Channel_3: TIM Channel 3
* @arg TIM_Channel_4: TIM Channel 4
* @param TIM_CCx: specifies the TIM Channel CCxE bit new state.
* This parameter can be: TIM_CCx_Enable or TIM_CCx_Disable.
* @retval None
*/
void TIM_CCxCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCx)
{
uint16_t tmp = 0;
/* Check the parameters */
assert_param(IS_TIM_LIST8_PERIPH(TIMx));
assert_param(IS_TIM_CHANNEL(TIM_Channel));
assert_param(IS_TIM_CCX(TIM_CCx));
tmp = CCER_CCE_Set << TIM_Channel;
/* Reset the CCxE Bit */
TIMx->CCER &= (uint16_t)~ tmp;
/* Set or reset the CCxE Bit */
//TIMx->CCER |= (uint16_t)(TIM_CCx << TIM_Channel); //原来的库函数错误
//修改为:
if(TIM_CCx==ENABLE) TIMx->CCER |= tmp;
}
/**
* @brief Enables or disables the TIM Capture Compare Channel xN.
* @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIM peripheral.
* @param TIM_Channel: specifies the TIM Channel
* This parameter can be one of the following values:
地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司
1
------------------------------------------------------------------------------------------------------------------------------------------------------STM32库函数TIM_CCxCmd()和TIM_CCxNCmd()错误
Hefei Fulaide Electronics Science&technology Co., Ltd.
* @arg TIM_Channel_1: TIM Channel 1
* @arg TIM_Channel_2: TIM Channel 2
* @arg TIM_Channel_3: TIM Channel 3
* @param TIM_CCxN: specifies the TIM Channel CCxNE bit new state.
* This parameter can be: TIM_CCxN_Enable or TIM_CCxN_Disable.
* @retval None
*/
void TIM_CCxNCmd(TIM_TypeDef* TIMx, uint16_t TIM_Channel, uint16_t TIM_CCxN)
{
uint16_t tmp = 0;
/* Check the parameters */
assert_param(IS_TIM_LIST2_PERIPH(TIMx));
assert_param(IS_TIM_COMPLEMENTARY_CHANNEL(TIM_Channel));
assert_param(IS_TIM_CCXN(TIM_CCxN));
tmp = CCER_CCNE_Set << TIM_Channel;
/* Reset the CCxNE Bit */
TIMx->CCER &= (uint16_t) ~tmp;
/* Set or reset the CCxNE Bit */
//TIMx->CCER |= (uint16_t)(TIM_CCxN << TIM_Channel); //原来的库函数错误
//修改为:
if(TIM_CCxN==ENABLE) TIMx->CCER |= tmp;
}
地址:安徽省、合肥市、肥东县、店埠镇,合肥市福来德电子科技有限公司
2


发布评论