Help, I can't find out why my TxD1 does not transmit.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help, I can't find out why my TxD1 does not transmit.

462 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ronald on Thu Feb 23 08:38:22 MST 2012
:confused:
I have a problem with the UART1 port (on P0.15 and P0.16). It sends no data.
My initialisation:
void Serial_init (void)
{
// TxD: Port 0.15
// RxD: Port 0.16
LPC_PINCON->PINSEL0 |= 0x40000000;
LPC_PINCON->PINSEL1 |= 0x00000001;
LPC_PINCON->PINMODE0 |= 0x80000000;
LPC_PINCON->PINMODE1 |= 0x00000002;
// Initialisation routines
LPC_SC->PCONP |= 0x00000010; // Set PCUART bit
LPC_SC->PCLKSEL0 |= 0x00000100; // Set PCLK_UART1 to 0x01 = CCLK/1
LPC_UART1->LCR |= 0x83; // 8 bits, 1 stopbit, no parity, DLAB = 1

// Baudrate: 19.200 Baud
LPC_UART1->DLM = 0;
LPC_UART1->DLL = 52;
LPC_UART1->LCR |= 0x03; // 8 bits, 1 stopbit, no parity, DLAB = 0
LPC_UART1->FDR = 0x01; // DIVADDVAL = 0 -- MULVAL = 1
LPC_UART1->FCR |= 0x07; // FIFO Enable
LPC_UART1->TER |= 0x80;
LPC_UART1->IER |= 0x02;
}

For sending a character, I use the following code:

unsigned char UART1_PutChar (unsigned char ch)
{
while (!(LPC_UART1->LSR & 0x20));
return (LPC_UART1->THR = ch);
}

Nothing happens on TxD1.
Please, can anyone tell me why.
0 Kudos
7 Replies

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ronald on Thu Feb 23 15:47:44 MST 2012
Thank you very, very much. This las (LDR) register was the real problem. I changed the '0' and the '1'. I feel very foolish, but I'am very thankfull.  :)
0 Kudos

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 23 12:23:30 MST 2012
Try:

void RS485_init (void)
{
// TxD: Port 0.15
// RxD: Port 0.16
LPC_PINCON->PINSEL0 &= ~0xC0000000;
LPC_PINCON->PINSEL0 |=  0x40000000;
LPC_PINCON->PINSEL1 &= ~0x00000003;
LPC_PINCON->PINSEL1 |=  0x00000001;
// Initialisation routines
LPC_SC->PCONP |=(1 <<4); // Set PCUART bit
LPC_UART1->LCR = 0x83; // 8 bits, 1 stopbit, no parity, DLAB = 1
//Baudrate: 25E6/16/81 = 19.290 Baud
LPC_UART1->DLM = 0;
LPC_UART1->DLL = 81;
LPC_UART1->LCR = 0x03; // 8 bits, 1 stopbit, no parity, DLAB = 0
LPC_UART1->FCR = 0x07; // FIFO Enable
}
The reason why your code wasn't running was this line:
LPC_UART1->FDR = 0x01;         // DIVADDVAL = 0 -- MULVAL = 1
This is an invalid FDR setting and therefore killed your code :eek::eek:

UM:

Quote:

Table 285: UARTn Fractional Divider Register (U0FDR - address 0x4000 C028, U2FDR - 0x4009 8028, U3FDR - 0x4009 C028) bit description

3:0 DIVADDVAL  Baud-rate generation pre-scaler divisor value. If this field is 0, fractional baud-rate generator will not impact the UARTn baudrate.

7:4 MULVAL  Baud-rate pre-scaler multiplier value. [B][COLOR=Red]This field must be greater or equal 1 for UARTn to operate properly, regardless of whether the fractional baud-rate generator is used or not.[/COLOR][/B]

0 Kudos

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ronald on Thu Feb 23 11:42:35 MST 2012
Still the same reaction. The THR stays full.
[FONT=Arial][COLOR=#7f0055][B][COLOR=#7f0055]void R[/COLOR][/B][/COLOR][B]S485_init[/B] ([B][COLOR=#7f0055][COLOR=#7f0055]void[/COLOR][/COLOR][/B]) [/FONT]
[LEFT][FONT=Arial][COLOR=#3f7f5f][COLOR=#3f7f5f]// TxD: Port 0.15[/COLOR][/COLOR][/FONT][LEFT][FONT=Arial][COLOR=#3f7f5f][COLOR=#3f7f5f]// RxD: Port 0.16[/COLOR][/COLOR]LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINSEL0[/COLOR][/COLOR] &= ~0xC0000000;LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINSEL0[/COLOR][/COLOR] |= 0x40000000;LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINSEL1[/COLOR][/COLOR] &= ~0x00000003;[/FONT][/LEFT]

[LEFT][FONT=Arial]LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINSEL1[/COLOR][/COLOR] |= 0x00000001;[/FONT][/LEFT]
[/LEFT]
[FONT=Arial]LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINMODE0[/COLOR][/COLOR] &= ~0xC0000000;[/FONT][LEFT][FONT=Arial]LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINMODE0[/COLOR][/COLOR] |= 0x80000000;[/FONT][LEFT][FONT=Arial]LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINMODE1[/COLOR][/COLOR] &= ~0x00000003;LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINMODE1[/COLOR][/COLOR] |= 0x00000002;[/FONT][/LEFT]

[FONT=Arial][COLOR=#3f7f5f][COLOR=#3f7f5f]// Initialisation routines[/COLOR][/COLOR]LPC_SC->[COLOR=#0000c0][COLOR=#0000c0]PCONP[/COLOR][/COLOR] |= 0x00000010; [COLOR=#3f7f5f][COLOR=#3f7f5f]// Set PCUART bit[/COLOR][/COLOR][/FONT][/LEFT]
[FONT=Arial]LPC_SC->[COLOR=#0000c0][COLOR=#0000c0]PCLKSEL0[/COLOR][/COLOR] |= 0x00000100; [COLOR=#3f7f5f][COLOR=#3f7f5f]// Set PCLK_UART1 to 0x01 = CCLK/1[/COLOR][/COLOR]LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]LCR[/COLOR][/COLOR] = 0x83; [COLOR=#3f7f5f][COLOR=#3f7f5f]// 8 bits, 1 stopbit, no parity, DLAB = 1[/COLOR][/COLOR] [COLOR=#3f7f5f][COLOR=#3f7f5f]// Baudrate: 19.200 Baud[/COLOR][/COLOR][/FONT][LEFT][FONT=Arial]LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]DLM[/COLOR][/COLOR] = 0;[/FONT][/LEFT]
[FONT=Arial]LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]DLL[/COLOR][/COLOR] = 52;[/FONT][LEFT][FONT=Arial]LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]LCR[/COLOR][/COLOR] = 0x03; [COLOR=#3f7f5f][COLOR=#3f7f5f]// 8 bits, 1 stopbit, no parity, DLAB = 0[/COLOR][/COLOR][/FONT][LEFT][FONT=Arial]LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]FDR[/COLOR][/COLOR] = 0x01; [COLOR=#3f7f5f][COLOR=#3f7f5f]// DIVADDVAL = 0 -- MULVAL = 1[/COLOR][/COLOR][/FONT][/LEFT]
[/LEFT]
[FONT=Arial]LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]FCR[/COLOR][/COLOR] = 0x07; [COLOR=#3f7f5f][COLOR=#3f7f5f]// FIFO Enable[/COLOR][/COLOR][/FONT][LEFT][FONT=Arial]}[/FONT][/LEFT]
[FONT=Arial] [/FONT][LEFT][FONT=Arial]AND[/FONT][/LEFT]
[FONT=Arial] [/FONT][LEFT][FONT=Arial][B][COLOR=#7f0055][COLOR=#7f0055]void [/COLOR][/COLOR][/B][B]UART1_PutChar[/B] ([B][COLOR=#7f0055][COLOR=#7f0055]unsigned[/COLOR][/COLOR][/B][B][COLOR=#7f0055][COLOR=#7f0055]char[/COLOR][/COLOR][/B] ch)[/FONT][/LEFT]
[FONT=Arial]{[/FONT][LEFT][FONT=Arial][B][COLOR=#7f0055][COLOR=#7f0055]     while[/COLOR][/COLOR][/B] (!(LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]LSR[/COLOR][/COLOR] & 0x20)){[/FONT][LEFT][FONT=Arial]              led_red_on();     }     led_red_off();     LPC_UART1->[COLOR=#0000c0][COLOR=#0000c0]THR[/COLOR][/COLOR] = ch;}[/FONT][/LEFT]

[FONT=Arial][SIZE=2]Now I do have a reaction, but the THRE-bit stays to zero and no byte is send through TxD.[/SIZE][/FONT][/LEFT]
[I][COLOR=#5174a3]Last edited by Ronald[/COLOR]; 02-23[/I]
0 Kudos

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 23 11:21:18 MST 2012

Quote:
[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINSEL1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= !0x00000003;  [/SIZE]:eek::eek:

Do not use logical NOT (!), use bitwise NOT (~)

[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINSEL1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= ~0x00000003;[/SIZE]
0 Kudos

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ronald on Thu Feb 23 11:04:02 MST 2012
Thanks, now I have chaged my code to:

 
[SIZE=2][COLOR=#7f0055][B][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/B]
[LEFT][/COLOR][/SIZE][SIZE=2][B]RS485_init[/B] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE][/LEFT]
 
[LEFT][SIZE=2]{[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// TxD: Port 0.15[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// RxD: Port 0.16[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINSEL0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= 0x3FFFFFFF;[/SIZE][/LEFT]
[/LEFT]

[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINSEL0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= 0x40000000;[/SIZE]
[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINSEL1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= 0xFFFFFFFC;[/SIZE]
[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINSEL1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= 0x00000001;[/SIZE]

[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINMODE0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= 0x3FFFFFFF;[/SIZE]
[SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINMODE0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= 0x80000000;[/SIZE]

[LEFT][SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINMODE1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] &= 0xFFFFFFFC;[/SIZE]
[LEFT][SIZE=2]LPC_PINCON->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PINMODE1[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= 0x00000002;[/SIZE][/LEFT]
[/LEFT]

[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][/COLOR][/SIZE][/COLOR][/SIZE] 
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Initialisation routines[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]LPC_SC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PCONP[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= 0x00000010; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set PCUART bit[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]LPC_SC->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]PCLKSEL0[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] |= 0x00000100; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Set PCLK_UART1 to 0x01 = CCLK/1[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LCR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0x83; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// 8 bits, 1 stopbit, no parity, DLAB = 1[/COLOR][/SIZE][/COLOR][/SIZE]
 
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Baudrate: 19.200 Baud[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2]LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DLM[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0;[/SIZE]
[SIZE=2]LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DLL[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 52;[/SIZE]
[LEFT][SIZE=2]LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LCR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0x03; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// 8 bits, 1 stopbit, no parity, DLAB = 0[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2]LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]FDR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0x01; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// DIVADDVAL = 0 -- MULVAL = 1[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]

[SIZE=2]LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]FCR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0x07; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// FIFO Enable[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//LPC_UART1->TER = 0x80;[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
 
 
[LEFT]AND[/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][B]UART1_PutChar[/B] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]unsigned[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]char[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ch)[/SIZE][/LEFT]
[SIZE=2]{[/SIZE]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]     while[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (!(LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LSR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] & 0x20)){[/SIZE]

[SIZE=2]             led_red_on();[/SIZE]
[LEFT][SIZE=2]    }[/SIZE]
[SIZE=2]    led_red_off();[/SIZE]
[SIZE=2]    LPC_UART1->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]THR[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = ch;[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]

 
 
 
 
 


[LEFT]Now I do have a reaction, but the THRE-bit stays to zero and no byte is send through TxD.[/LEFT]
0 Kudos

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 23 09:10:48 MST 2012
There's an nice UART sample for UART0: RDB1768cmsis2_UART_printf

It's init is doing all the baudrate stuff for you and changing it to UART1 doesn't seem so difficult :rolleyes:

// ***********************
// Function to set up UART
void UART0_Init(int baudrate)
{
    int pclk;
    unsigned long int Fdiv;

    // PCLK_UART0 is being set to 1/4 of SystemCoreClock
    pclk = SystemCoreClock / 4;    
    
    // Turn on power to UART0
    LPC_SC->PCONP |=  PCUART0_POWERON;
        
    // Turn on UART0 peripheral clock
    LPC_SC->PCLKSEL0 &= ~(PCLK_UART0_MASK);
    LPC_SC->PCLKSEL0 |=  (0 << PCLK_UART0);        // PCLK_periph = CCLK/4
    
    // Set PINSEL0 so that P0.2 = TXD0, P0.3 = RXD0
    LPC_PINCON->PINSEL0 &= ~0xf0;
    LPC_PINCON->PINSEL0 |= ((1 << 4) | (1 << 6));
    
    LPC_UART0->LCR = 0x83;        // 8 bits, no Parity, 1 Stop bit, DLAB=1
    Fdiv = ( pclk / 16 ) / baudrate ;    // Set baud rate
    LPC_UART0->DLM = Fdiv / 256;                            
    LPC_UART0->DLL = Fdiv % 256;
    LPC_UART0->LCR = 0x03;        // 8 bits, no Parity, 1 Stop bit DLAB = 0
    LPC_UART0->FCR = 0x07;        // Enable and reset TX and RX FIFO
}
0 Kudos

443 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Thu Feb 23 08:50:28 MST 2012
Get rid of some "|=" operators, replacing them with "=". In particular this:
"LPC_UART1->LCR |= 0x03; // 8 bits, 1 stopbit, no parity, DLAB = 0 "
will not allow to access Tx and Rx data registers, as it does not set DLAB to 0;
0 Kudos