如何使用 STM32 _Msk 和 _Pos 定义来读写寄存器
STM32 HAL 包含类似 TIM_CR1_CKD_Msk 或 TIM_CR1_CKD_Pos 的定义,你可以使用它们更轻松地读取或写入寄存器的一部分。
读取寄存器的一部分
read_register.cpp
uint32_t ckd = (TIM1->CR1 & TIM_CR1_CKD_Msk) >> TIM_CR1_CKD_Pos;写入寄存器的一部分
write_register.cpp
uint32_t new_ckd_value = TIM_CLOCKDIVISION_DIV4; // 示例
TIM1->CR1 &= TIM_CR1_CKD_Msk; // 清除位
TIM1->CR1 |= new_ckd_value << TIM_CR1_CKD_Pos; // 设置位
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow