我想用外部8M的时钟,请哪位大神指导一下,我配的时钟寄存器有没有错。或者有没有人解答一下,飞思卡尔K系列单片机怎么配置使用外部晶振。
SIM->CLKDIV1 = (uint32_t)0xFFFFFFFFu;
SIM_SCGC5 |=SIM_SCGC5_PORTA_MASK;
/* MCG_C2: LOCRE0=0,RANGE=2,HGO=0,EREFS=1,LP=0,IRCS=0 */
MCG->C2 = (uint8_t)((MCG_C2 & (uint8_t)~(uint8_t)( MCG_C2_LOCRE0_MASK |
MCG_C2_RANGE(0x01) |
MCG_C2_HGO_MASK |
MCG_C2_LP_MASK |
MCG_C2_IRCS_MASK )) |
(uint8_t)(MCG_C2_RANGE(0x01) |
MCG_C2_HGO_MASK |
MCG_C2_EREFS_MASK ));
/* MCG_C1: CLKS=0,FRDIV=3,IREFS=0,IRCLKEN=0,IREFSTEN=0 */
MCG->C1 |=MCG_C1_CLKS(0x02) |
MCG_C1_FRDIV(0x04)|MCG_C1_IREFS_MASK;
/* MCG_C4: DMX32=0,DRST_DRS=0 */
MCG_C4 &= (uint8_t)~(uint8_t)((MCG_C4_DMX32_MASK | MCG_C4_DRST_DRS(0x03)));
/* OSC_CR: ERCLKEN=1,??=0,EREFSTEN=0,??=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
OSC_CR = OSC_CR_ERCLKEN_MASK;
/* MCG_C7: OSCSEL=0 */
MCG_C7 &= (uint8_t)~(uint8_t)(MCG_C7_OSCSEL(0x03));
while((MCG->S & MCG_S_OSCINIT0_MASK) == 1u);
while((MCG->S & MCG_S_IRCST_MASK) != 0u);
while((MCG->S & 0x0Cu) != 0x08u);
此帖出自
小平头技术问答
一周热门 更多>