我正在尝试通过 pic18f45k22 eusart 外围设备传输串行。当时钟以 16Mhz 运行时,消息完全按预期发送,但如果我将 PLL 设置为打开(以便振荡器以 64Mhz 运行),则会出现帧错误。
我已经更改了 SPBRG 寄存器以考虑新的时钟频率,并尝试将波特率发生器更改为 16 位和 8 位模式,但没有任何乐趣。
当前代码:
OSCCONbits.IRCF = 0b111; //change Fosc to 16Mhz
OSCTUNEbits.PLLEN = 1; //enable PLL to multiply Fosc by 4
/*Set baud rates and related registers*/
/*For BRG16 = 1 and BRGH = 1, Baud rate = Fosc/(4([SPBRG:SPBRGH]+1)) */
SPBRGH1 = 0; //Set Baud rate control regs to 34 to give baudrate of 115.2k
SPBRG1 = 138;
BAUDCON1bits.BRG16 = 1; //16 bit mode (baudrate generator)
TXSTAbits.BRGH = 1; //Set high speed baud rate
提前致谢, Huggzorx