64Mhz 时钟的 PIC18f45k22 串行帧错误
我正在尝试通过 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
提前致谢, 哈格佐克斯
I'm trying to transmit serial over the pic18f45k22 eusart peripheral. The messages get sent exactly as expected when the clock is running at 16Mhz, but if I set the PLL to on (so that the the oscillator runs at 64Mhz), I get a framing error.
I have changed the SPBRG registers to account for the new clock frequencey, and tried changing the baudrate generator to both 16 and 8 bit modes, but with no joy.
Current code:
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
Thanks in advance,
Huggzorx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉那个特定的芯片,但总的来说,当我的 UART 不工作时,我会看到这个。
1)你的时钟可以分频到波特率且误差足够小吗?假设评论中的波特率公式是正确的,我认为你没问题:
2)确保你的芯片产生你认为应该产生的波特率。有些 PLL 对开启方式非常挑剔。外围设备也很容易配置错误。我发现示波器是诊断此类问题的最佳选择。如果您有权访问其中一个,请检查 PIC 的发送引脚并检查您的位宽度是否为 8.68us (1/115200)。
如果它是该大小的 4 倍(34.72us),那么您的 PLL 没有锁定。如果只是有点偏差,那么公式可能是错误的。
虽然不多,但希望它能让您朝着正确的方向前进。
I'm not familiar with that specific chip but in general, this is what I look at when my UART isn't behaving.
1) Can your clock be divided down to the baud rate with little enough error. Assuming that your baud rate formula in the comments is correct, I think you're okay there:
2) Make sure your chip is producing the baud rate you think it should be producing. Some PLLs are really picky about how you turn them on. It's also easy to mis-configure a peripheral. I find that an oscilloscope is your best bet to diagnose this type of problem. If you have access to one, scope the PIC's transmit pin and check that your bit width is 8.68us (1/115200).
If it's 4 times that size (34.72us), then your PLL didn't lock. If it's just a bit off, then the formula might be wrong.
It's not much but hopefully it gets you going in the right direction.