CHECK AND MODIFY MCO ON STM32

查错

下面代码控制HSI作为MCO输出

  /*CONFIGURE PA8为Alternate Function*/
#define  GPIOBBASE  0X40010C00ul
#define  GPIOABASE  0x40010800UL
#define  RCCBASE  0X40021000ul
  
 /*HSION, open bit 0*/
 *(volatile uint32_t*)(RCCBASE + 0X0) |=(0x1ul) << 0u; 
/*check ready or not HSIRDY*/
  while((*(volatile uint32_t*)RCCBASE) & 0x1ul != 0x1ul );
  
  /*配置PA8,CNF8,alternate pp模式, close bit [3.2]*/
  *(volatile uint32_t*)(GPIOABASE + 0X00) |= (~0x2ul) << 2u; 
  /*配置PB3,MODE3,50Mhz*/
  *(volatile uint32_t*)(GPIOABASE + 0X00) |= (0x3ul) << 0u; 
  
 *(volatile uint32_t*)(RCCBASE + 0X18) |= (0x1UL);/*RCC_APB2ENR, AFIO开启*/
 //*(volatile uint32_t*)(RCCBASE + 0X04) |=(0x101ul) << 24u; /*选择那个时钟输出*/
 *(volatile uint32_t*)(RCCBASE + 0X04) |=(0x5ul) << 24u; /*选择那个时钟输出*/ 

掩码设置错误,应为0x2ul.

/*check ready or not HSIRDY*/
while((*(volatile uint32_t*)RCCBASE) & 0x1ul != 0x1ul );

配置PA8,在设置CNY8时,有两个位需要设置,且两个位设置不同,怎么办?

先清零,然后设置。

  /*配置PA8,CNF8,alternate pp模式, close bit [3.2]*/
  *(volatile uint32_t*)(GPIOABASE + 0X00) &= (0x2ul) << 2u; 
  *(volatile uint32_t*)(GPIOABASE + 0X00) |= (0x2ul) << 2u; 
  /*配置PB3,MODE3,50Mhz*/
  *(volatile uint32_t*)(GPIOABASE + 0X00) |= (0x3ul) << 0u; 


posted on 2022-09-08 16:26  大胆前进错了就问  阅读(24)  评论(0编辑  收藏  举报

导航