beautypg.com

Sundance SMT118 User Manual

Page 19

background image

Version 1.0

Page 19 of 20

SMT118v2 User Manual


The following function is the basic UART transmit data routine. Supply the UART
number (0 to 3) and the data.

tx_uart(int uart, int data)
{
// Wait for bit 6 of the UART status register to become set
// indicating that there is an empty space in the transmit
// FIFO.
while( ((read_uart(uart, 5)) & 0x40) == 0 );
write_uart(uart, 0, data);
}


The following function shows how to initialise the UARTs for operation at 9600 baud.
The divisor is calculated as follows:

divisor = 1.8432e6 / (16 * baud rate)

The 1.8432MHz external clock is supplied by a crystal oscillator, and is such that
most standard baud rates can be produced exactly.

// Repeat process for all UART channels.
for(u=0;u!=4;u++) {

// Select the UART divisor register.
write_uart(u, 3, 0x83);

// Set divisor to 0x000C (12).
write_uart(u, 0, 0x0C); // least significant byte
write_uart(u, 1, 0x00); // most significant byte

// Select the normal UART registers.
write_uart(u, 3, 0x03);
}