Dear all,
I am trying to connect a GPS receiver to M5213EVB and using UART on M5213EVB to transmit the GPS data to computer screen. I know I have to initialize the PORTUB (RXD0 and TXD0) and set the baudrate to 4800, 8 data bit, no parity, 1 stop bit, no flow control. I am thinking that I could use on-chip 8MHz oscillator and set PLLMODE to mormal mode, set low power divider as "0000", use system clock as UART clock.
My questions are: How do I set up baud rate? According my setup above, the system clock is 8 MHz, so
do I need to adjust MCF_UART1_UBG1 and UBG2? What exactly are UBG1 and UGB2 register for?
Here is my code for initialization, could someone check it for me, please!
Thanks!!
#include <stdio.h>
#include "mcf5213.h"
#include "common.h"
#include "uart.h"
#include "clock.h"
void Init_CLK(void)
{
MCF_CLOCK_SYNCR = 0x07; //set PPLMODE='1',PPLEN='1',CLKsrc='1'
MCF_CLOCK_LPCR_LPD(4); //set LPD="0000"
MCF_PMM_PPMRL = 0x00000040; //enable UART use system clock
}
void Init_UART1(void)
{
uint16 ubgs;
// assign port pins to UART functions
MCF_GPIO_PUBPAR = 0 | MCF_GPIO_PUBPAR_TXD1_TXD1 | MCF_GPIO_PUBPAR_RXD1_RXD1;
// Reset Receiver and Transmitter (UCR)
MCF_UART1_UCR = MCF_UART_UCR_RESET_TX;
MCF_UART1_UCR = MCF_UART_UCR_RESET_RX;
// Reset Mode Pointer
MCF_UART1_UCR = MCF_UART_UCR_RESET_MR;
// Initialize Input Enable Control (UACR)
MCF_UART1_UACR = 0;
// Select Receiver and Transmitter Clock (UCSR)
ubgs = ((8*1000000)/(4800 * 32));
MCF_UART1_UBG1 = (uint8)((ubgs & 0xFF00) >> 8); //divider MSB
MCF_UART1_UBG2 = (uint8)(ubgs & 0x00FF); //divider LSB
//Set Rx and Tx clocks to system clock
MCF_UART1_UCSR = 0 | MCF_UART_UCSR_TCS(MCF_UART_UCSR_TCS_SYS_CLK)
| MCF_UART_UCSR_RCS(MCF_UART_UCSR_TCS_SYS_CLK);
// Set Mode Register 1 (UMR1)
MCF_UART1_UMR = 0 // RX Ready will generate interrupt
| MCF_UART_UMR_BC_8 // 8 bits/char
| MCF_UART_UMR_PM_NONE; // no parity
// Set Mode Register 2 (UMR2)
MCF_UART1_UMR = 0 // normal mode
| MCF_UART_UMR_SB_STOP_BITS_15; // stop bit width
// Enable Transmitter and Receiver (UCR)
MCF_UART1_UCR = 0 | MCF_UART_UCR_TX_ENABLED | MCF_UART_UCR_RX_ENABLED;
}