UART 只接收 FF 和 FE

问题描述

我目前正在通过 FT232 从 PIC18F4620 传输到 CoolTerm。不过,我目前只收到来自 PIC 的 FF 和 FE。我想知道为什么会这样。 Rx - TX 已正确切换,连接它们的电缆似乎是安全的。我能想到的唯一问题是波特率不正确,但查看数据表我不相信。任何见解将不胜感激。 (我随意选择了 51 作为我的测试编号。任何数字或字母都可以)。

Circuit



const unsigned char MSG0[] = "Transmitting... ";
const unsigned char MSG1[] = "Sent:";
const unsigned char MSG2[] = "TEST:";

// Subroutine Declarationsb
#include <pic18.h>

// Subroutines
#include        "lcd_portd.c"

#include <delays.h>
#include <plib.h>
#include <stdint.h>

void UART_TX_Init(void)
{
    BRG16 = 0;
    BRGH = 1; // Set For High-Speed Baud Rate
    SPBRG = 64; // Set The Baud Rate To Be 9600 bps
  //--[ Enable The Ascynchronous Serial Port ]--
    SYNC = 0;
    SPEN = 1;
  //--[ Set The RX-TX Pins to be in UART mode (not io) ]--
    TRISC6 = 1;  // As stated in the datasheet
    TRISC7 = 1;  // As stated in the datasheet
    TXEN = 1; // Enable UART Transmission
}

void UART_Writes(uint8_t data)
{
    while(!TRMT);
    TXREG = data;
}

// Main Routine
void main(void)
{
    UART_TX_Init();
    unsigned int result = 0;
    unsigned int i;
    uint8_t      data = 51;
    TRISA = 0;
    TRISC = 0;
    TRISB = 0;
    TRISD = 0;
    TRISE = 0;
    TRISA = 0;
    TRISB = 0x00;
    PORTC = 0;
    PORTD = 0;
    PORTE = 0;
    ADCON1 = 0x0F;

    LCD_Init();                  // initialize the LCD
    LCD_Move(0,0);  for (i=0; i<20; i++) LCD_Write(MSG0[i]); 
    Wait_ms(100); 
    LCD_Move(1,0);  for (i=0; i<5; i++) LCD_Write(MSG1[i]); 
    while(1) {
        Wait_ms(1000);
        UART_Writes(data);
        LCD_Move(1,5); LCD_Out(data,3,0);
    }
}


CoolTerm

解决方法

您的时钟频率是多少?您是如何配置晶体振荡器的?请分享您的时钟设置和配置。

如果时钟设置正常,则计算正确的波特率并尝试。

void UART_Writes(uint8_t data)
{

while(!TRMT)
{
  //put Nop() and try
}
    TXREG = data;
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...