beautypg.com

Read / write to rs232 – Sundance SMT118 User Manual

Page 18

background image

Version 1.0

Page 18 of 20

SMT118v2 User Manual

Read / Write to RS232
The following functions give an easy interface to the RS232 channels when
configured for simple Tx/Rx operation.
The following function is the basic UART register read routine. Supply the UART
number (0 to 3) and the register number (0 to 7).

#define uart_base 0xF9000000

int read_uart(int uart, int uart_reg)
{
int data;
data = read_global(uart_base + uart*8 + uart_reg);
return(data);
}

The following function is the basic UART register write routine. Supply the UART
number (0 to 3), the register number (0 to 7) and the required data.

write_uart(int uart, int uart_reg, int data)
{
write_global(uart_base + uart*8 + uart_reg, data);
}

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

int rx_uart(int uart)
{
volatile int t;
// Wait for bit 0 of the UART status register to become set
// indicating that there is data in the receive FIFO.
while( ( (t=read_uart(uart, 5)) & 0x01) == 0 );
return(read_uart(uart, 0));
}