參考 STM32 USART出現亂碼
在使用超級終端Tera Team軟體除錯CC3200 UART示例程式時,界面總是輸出亂碼,

參考了另外一篇博客之后,提出有可能是波特率設定的問題,在設定里面,發現設定的波特率為9600bit/s,

void
UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
unsigned long ulBaud, unsigned long ulConfig)
{
unsigned long ulDiv;
//
// Check the arguments.
//
ASSERT(UARTBaseValid(ulBase));
ASSERT(ulBaud != 0);
//
// Stop the UART.
//
UARTDisable(ulBase);
//
// Is the required baud rate greater than the maximum rate supported
// without the use of high speed mode?
//
if((ulBaud * 16) > ulUARTClk)
{
//
// Enable high speed mode.
//
HWREG(ulBase + UART_O_CTL) |= UART_CTL_HSE;
//
// Half the supplied baud rate to compensate for enabling high speed
// mode. This allows the following code to be common to both cases.
//
ulBaud /= 2;
}
else
{
//
// Disable high speed mode.
//
HWREG(ulBase + UART_O_CTL) &= ~(UART_CTL_HSE);
}
//
// Compute the fractional baud rate divider.
//
ulDiv = (((ulUARTClk * 8) / ulBaud) + 1) / 2;
//
// Set the baud rate.
//
HWREG(ulBase + UART_O_IBRD) = ulDiv / 64;
HWREG(ulBase + UART_O_FBRD) = ulDiv % 64;
//
// Set parity, data length, and number of stop bits.
//
HWREG(ulBase + UART_O_LCRH) = ulConfig;
//
// Clear the flags register.
//
HWREG(ulBase + UART_O_FR) = 0;
//
// Start the UART.
//
UARTEnable(ulBase);
}
上面是CC3200 SDK提供的API函式,主要是為了配置UART介面,其中函式第三個引數ulBaud就是指波特率,
void
InitTerm()
{
#ifndef NOTERM
MAP_UARTConfigSetExpClk(CONSOLE,MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH),
UART_BAUD_RATE, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
#endif
__Errorlog = 0;
}
上面是主函式里的初始化終端函式,就是參考了UAET的API函式對UART進行初始化,我們看到第三個引數為UART_BAUD_RATE,這個就是波特率,這是一個宏定義,我們去找找它定義為了多少,
#define UART_BAUD_RATE 115200
#define SYSCLK 80000000
#define CONSOLE UARTA0_BASE
#define CONSOLE_PERIPH PRCM_UARTA0
在uart_if.h這個頭檔案,可以發現波特率被設定為了115200,接下來我們去修改超級終端的波特率,重新運行,發現亂碼問題已經解決了,


轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/196170.html
標籤:AI
上一篇:樹莓派ubuntu mate16.04安裝ROS-Kinetic和Turtlebot2
下一篇:基于RT1064的電磁巡線小車
