
VMX51C1020
_________________________________________________________________________________________________
www.ramtron.com
page 42 of 80
The following formulas are used to calculate the
baud Rate, S1RELL and S1RELH values.
Serial 1
Baud Rate= f
32 x (1024-S1REL)
Note: S1REL.9-0 = S1RELH.1-0 + S1RELL.7-0
S1REL = 1024 - f
clk__________
32 x Baud Rate
T
ABLE
77:
S
ERIAL
1
B
AUD
R
ATE
S
AMPLE
V
ALUES
Desired
Baud Rate
f
= 11.0592
MHz
500.0 kbps
-
460.8 kbps
-
230.4 kbps
-
115.2 kbps
3FDh
57.6 kbps
3FAh
19.2 kbps
3EEh
9.6 kbps
3DCh
2.4 kbps
370h
1.2 kbps
2E0h
Setting Up and Using UART1
S1REL @
S1REL @
f
= 14.746
MHz
-
3FFh
3FEh
3FCh
3F8h
3E8h
3D0h
34Fh
280h
In order to use UART1, the following operations
must be performed:
o
Enable the UART1 Interface
o
Set I/O Pad direction
TX= output, RX=Input
o
Enable Reception (if required)
o
Configure the UART1 controller S1CON
Example of UART1 Setup and Use
The following are C code examples of UART1
configuration, serial byte transmission and
interrupt usage.
//----------------------------------------------------------------------------------------//
// UART1 CONFIG
//
// Configure the UART1 to operate in RS232 mode at 115200bps
// with a crystal of 14.7456MHz
//----------------------------------------------------------------------------------------//
void uart1Config(void)
{
P0PINCFG |= 0x04;
// pads for uart 1
DIGPWREN |= 0x02;
// enable uart1
S1RELL = 0xFC;
// Set com speed = 115200bps
S1RELH = 0x03;
S1CON = 0x90;
// Mode B, receive enable
}//end of uart1Config() function
//----------------------------------------------------------------------------------------//
// TXMIT1 -- Transmit one byte on the UART1
//----------------------------------------------------------------------------------------//
void txmit1( unsigned char charact){
S1BUF = charact;
USERFLAGS = S1CON;
while (!UART_TX_EMPTY) {USERFLAGS = S1CON;}
S1CON = S1CON & 0xFD;
}//end of txmit1() function
//----------------------------------------------------------------------------------------//
// Interrupt configuration
//---------------------------------------------------------------------------------------//
IEN0 |= 0x80;
// Enable all interrupts
IEN2 |= 0x01;
// Enable interrupt UART 1
//----------------------------------------------------------------------------------------//
// Interrupt function
//----------------------------------------------------------------------------------------//
void int_serial_1 (void) interrupt 16
{
IEN0 &= 0x7F;
// Disable all interrupts
/*------------------------*/
/*Interrupt code here*/
/*------------------------*/
if (S1CON&0x01==0x01)
{
S1CON &= 0xFE;
// Clear RI (it comes
// before T1I)
}
else
{
S1CON &= 0xFD;
// Clear T1I
}
IEN0 |= 0x80;}
// Enable all interrupts
}
}
/-----------------------------------------------------------------------
//Wait TX EMPTY flag
//clear both R1I & T1I bits