• Aucun résultat trouvé

MACC-05007 LPC2xxx UART transmitter code example

N/A
N/A
Protected

Academic year: 2022

Partager "MACC-05007 LPC2xxx UART transmitter code example"

Copied!
2
0
0

Texte intégral

(1)

MACC-05007

LPC2xxx UART transmitter code example

Author: Paul Seerden 2005 September 19

Microcontroller Applications

Philips

Semiconductors

ABSTRACT

This technical note gives a software example of how to effectively use the transmit FIFO of UART1 (same for UART0) of the Philips Semicon- ductors LPC2000 family.

Disclaimer

Described applications are for illustrative purposes only. Philips Semiconductors makes no representation or warranty that such applications will be suitable for the specified use without further testing or modification.

(2)

Technical note Philips Semiconductors

LPC2xxx UART transmitter code example MACC-05007

WORKING EXAMPLE

Applications using a UART to send data, normally have implemented a soft ware-based buffer (of for example 80 bytes) to feed the transmitter. The LPC2000 UART has a 16 byte transmit FIFO that can generate an interrupt when it is empty. There is how- ever no indication of buffer full, so often the question rises: “how do I know how many bytes can be written to the FIFO”.

Sometimes users try to write bytes to the FIFO as long as the THRE (Transmitter Holding Register Empty) bit is set. This will not work. It appears that whenever the THRE bit is set (interrupt) the FIFO is empty and a maximum of 16 bytes can be moved into the FIFO. The code example below is not interrupt driven. It just illustrates the part of moving bytes into the FIFO.

#define TX_BUFSIZE 80

static unsigned char txbuf[TX_BUFSIZE];

static unsigned char txptr = 0;

static unsigned char typtr = 0;

void UART1_Init(void) {

// Fpclk = 12.000.000 MHz

// DLM,DLH = Fpclk / (19200*16) = 39 = 0x27

PINSEL0 |= 0x00050000; // Select UART1 RXD/TXD

U1FCR = 7; // Enable and clear FIFO's U1LCR = 0x83; // 8N1, enable Divisor latch bit

U1DLL = 0x27; // baud rate fixed to 19200 @ PCLK = 12 Mhz U1DLM = 0;

U1LCR = 3; // Disable Divisor latch bit }

static void SendString(char *text) {

if (txptr == 0) // previous message send ? {

typtr = 0;

while(*text) {

txbuf[txptr++] = *text++;

if(txptr >= TX_BUFSIZE) txptr = 0;

} } }

static void UART1_Tx_Int(void) // Called from the main loop {

char i = 16;

if (U1LCR && 0x20) // transmit FIFO empty ? {

while (i && txptr) {

U1THR = txbuf[typtr++];

txptr --;

i --;

} } }

int main (void) {

UART1_Init();

while (1) {

SendString("Hello magnificent world of the LPC2000\r\n");

UART1_Tx_Int();

} }

Références

Documents relatifs

The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.. L’archive ouverte pluridisciplinaire HAL, est

Вне сомнений, русская история уникальна, но при этом отнюдь не локальна, не обособленна и не помечена вечным ордынским ярлыком евразийства.. Если рассматривать Запад

Tong, Area and perimeter, volume and surface area, College Math.?. Nelson, Volume and surface area for polyhedra and

Then, we know that in traditional technical documents, the answers are information units, which must be extracted automatically from the document, whereas in the

Supermarkets can be seen as a number of FIFO lanes in parallel, one for each part type produced in the system. Hence the material flow is very similar to FIFO

These initiatives are driven by such factors as the considerable impact of the Improvisation Technologies CD-ROM by William Forsythe, the interest of artists and the public to the

Fig.3 Index plots of clusters obtained for the care pathways of patients identified in 2007 after clustering with indel costs fixed at 0.9 and transition-based substitution

Concerning the Jews, the sources retained by the Brevarium include nine Roman laws derived from the Theodosian Code, the Novella 3 of Theodosius II, and two