1.既然ODR 能控制管脚高低电平为什么还需要BSRR和SRR(BRR?)寄存器?
对于问题 1------ 意法半导体给的答案是---
“This way, there is no risk that an IRQ occurs between the read and the modify access.”
什么意思呢?就就是你用BSRR和BRR去改变管脚状态的时候,没有被中断打断的风险。也就不需要关闭中断。
用ODR操作GPIO的伪代码如下:
disable_irq()
save_gpio_pin_sate = read_gpio_pin_state();
save_gpio_pin_sate = xxxx;
chang_gpio_pin_state(save_gpio_pin_sate);
enable_irq();
如果在代码第三行进入中断中改变了某个引脚的电平,save_gpio_pin_sate 可能会覆盖了前面改变引脚电平,所以控制GPIO的状态最好还是用SBRR和BRR