本帖最后由 永远不停 于 2021-5-10 20:03 编辑
如题,需要用到外部32K辅助振荡器,在SOSCO和SOSCI引脚间接入32K晶体
配置字里FEXTOSC 选为 LP(优化为32.768 kHz)
#pragma config FEXTOSC = LP // External Oscillator mode selection bits->Oscillator not enabled
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits->HFINTOSC (1MHz)
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; i/o or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit->FSCM timer enabled
// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit->MCLR pin is Master Clear function
#pragma config PWRTE = OFF // Power-up Timer Enable bit->PWRT disabled
#pragma config LPBOREN = OFF // Low-Power BOR enable bit->ULPBOR disabled
#pragma config BOREN = OFF // Brown-out reset enable bits->Brown-out Reset Enabled, SBOREN bit is ignored
#pragma config BORV = LO // Brown-out Reset Voltage Selection->Brown-out Reset Voltage (VBOR) set to 1.9V on LF, and 2.45V on F Devices
#pragma config ZCD = OFF // Zero-cross detect disable->Zero-cross detect circuit is disabled at POR.
#pragma config PPS1WAY = ON // Peripheral Pin Select one-way control->The PPSLOCK bit can be cleared and set only once in software
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a reset
// CONFIG3
#pragma config WDTCPS = WDTCPS_31 // WDT Period Select bits->Divider ratio 1:65536; software control of WDTPS
#pragma config WDTE = OFF // WDT operating mode->WDT Disabled, SWDTEN is ignored
#pragma config WDTCWS = WDTCWS_7 // WDT Window Select bits->window always open (100%); software control; keyed access not required
#pragma config WDTCCS = SC // WDT input clock selector->Software Control
// CONFIG4
#pragma config BBSIZE = BB512 // ->512 words boot block size
#pragma config BBEN = OFF // ->Boot Block disabled
#pragma config SAFEN = OFF // ->SAF disabled
#pragma config WRTAPP = OFF // ->Applic
#pragma congig WRTB = OFF
#pragma config WRTC = OFF
#pragma config WRTSAF = OFF
#pragma config LVP = ON
//CONFIG5
#pragma config CP = OFF
同时,时钟配置里选择为辅助振荡器,
OSCCON1 = 0x40; //选择新的时钟为SOSC
OSCCON2 = 0X60;
OSCCON3 = 0x00;
OSCEN = 0x00;
OSCFRQ = 0x00;
// HFTUN 0;
OSCTUNE = 0x00;
OSCCON3bits.SOSCPWR =1;//辅助振荡器工作在高功耗模式下
这样配置后晶体无法起振,请问用辅助振荡器还有哪里需要的配置?
|
用MCC配置试了一下,配置字FEXTOSC 仍然为 LP,但OSCCON1为0x70,即选择了EXTOSC,EXTOSC 按照 FEXTOSC 配置字,这样晶体就可以起振了,但辅助振荡器起振完成标志SOR并没有置1,反倒是外部晶体起振完成标志EXTOR被置1。有哪位大神帮忙讲解一下这究竟是为什么,完全搞不懂了