共2条
1/1 1 跳转至页
问
请教一下一个标称 4M Hz 的晶振它的值是 4000000 Hz 还是4×1024×1024 Hz?:confused:
答 1:
是前者,比如32KHZ的都是标注32.768。如果是4*1024*1024上面会标注:4.194304MHZ。
答 2:
可是无论我用4MHz还是4.194304MHz作UATR的波特率时钟,产生4800波特率都能正确发送数据。我想可能是在它的误差范围内,对吗?
答 3:
是的。通常串行每位的误差允许在20%以内。
答 4:
但是我发现接收时误码很高几乎是50%出错或根本接收不到,不知是什么原因?我的代码很简单就是设置接收中断
#include <MSP430x12x.h>
void main(void)
{
unsigned int i;
/**/
unsigned char send[34] = {0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62};
/**/
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG) != 0); // OSCFault flag still set?
BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe)
UCTL0 = CHAR; // 8-bit character
UTCTL0 = SSEL0; // UCLK = ACLK
UBR00 = 0x41; // 4Mhz/4800 - 833
UBR10 = 0x03; //
UMCTL0 = 0x44; //
ME2 |= UTXE0 + URXE0; // Enabled USART0 TXD/RXD
IE2 |= URXIE0; // Enabled USART0 RX interrupt
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10; // P3.4 output direction
_EINT(); // Enable interrupts
for (;;)
{
/**发送正常
for(i=0;i<34;i++)
{
while((IFG2 & UTXIFG0) == 0)
TXBUF0 = send[i];
}
**/
/**/
_BIS_SR(LMP3);
_NOP(); // Required only for C-spy
/**/
}
}
interrupt[UART0RX_VECTOR] void usart0_rx (void)
{
while ((IFG2 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}
#include <MSP430x12x.h>
void main(void)
{
unsigned int i;
/**/
unsigned char send[34] = {0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62,0x63,0x64,0x61,0x62,0x63,0x64
,0x61,0x62};
/**/
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 |= XTS; // ACLK = LFXT1 = HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG) != 0); // OSCFault flag still set?
BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe)
UCTL0 = CHAR; // 8-bit character
UTCTL0 = SSEL0; // UCLK = ACLK
UBR00 = 0x41; // 4Mhz/4800 - 833
UBR10 = 0x03; //
UMCTL0 = 0x44; //
ME2 |= UTXE0 + URXE0; // Enabled USART0 TXD/RXD
IE2 |= URXIE0; // Enabled USART0 RX interrupt
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10; // P3.4 output direction
_EINT(); // Enable interrupts
for (;;)
{
/**发送正常
for(i=0;i<34;i++)
{
while((IFG2 & UTXIFG0) == 0)
TXBUF0 = send[i];
}
**/
/**/
_BIS_SR(LMP3);
_NOP(); // Required only for C-spy
/**/
}
}
interrupt[UART0RX_VECTOR] void usart0_rx (void)
{
while ((IFG2 & UTXIFG0) == 0); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【笔记】生成报错synthdesignERROR被打赏50分 | |
【STM32H7S78-DK评测】LTDC+DMA2D驱动RGBLCD屏幕被打赏50分 | |
【STM32H7S78-DK评测】Coremark基准测试被打赏50分 | |
【STM32H7S78-DK评测】浮点数计算性能测试被打赏50分 | |
【STM32H7S78-DK评测】Execute in place(XIP)模式学习笔记被打赏50分 | |
每周了解几个硬件知识+buckboost电路(五)被打赏10分 | |
【换取逻辑分析仪】RA8 PMU 模块功能寄存器功能说明被打赏20分 | |
野火启明6M5适配SPI被打赏20分 | |
NUCLEO-U083RC学习历程2-串口输出测试被打赏20分 | |
【笔记】STM32CUBEIDE的Noruletomaketarget编译问题被打赏50分 |