Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

UART0, TC0, PWM & ADC at once on LPC2132

2005-11-23 by soren_t_hansen

Hi there

Im making a system where I'm using all the above mentioned interrupts.
I have had the TC0, PWM and the ADC running nicely until now, but when
I add the UART0 the TC0 goes dead (it's running a 1 Khz clock)

I want the UART0 to give me interrupts when it receives a byte and
only when that occours. When I send data I don't want to receive any
interrupts (It's a Master/Slave configuration where I send som
commands and the remote unit answers)

I have configured TC0 at Vic slot 0, the ADC at 1 and now the UART0 at 2.

I've read some posts that could indicate that all those interrupts
might not work together. On the other hand, it could be my init or ISR
that is wrong ...

My init and ISR for the UART0 is as follows:
void UART::init()
{
  PINSEL0 |= 0x000000005;         // Enable RxD0 and TxD0              
  U0LCR = 0x03;                   // 8 bits, no Parity, 1 Stop bit 
  U0IER = 0;                      // Disable UART0 RX 

  setBaudRate(9600);              // 9600 Baud Rate @ 15MHz VPB Clock  
  
  VICVectAddr2 = (unsigned long)UART_ISR;
  VICVectCntl2 = 0x20 | 6; /* UART1 Interrupt */
  VICIntEnable = 1 << 6;   /* Enable UART1 Interrupt */

  U0FCR = 0x07;             // Enable FIFOs and reset them 
  U0IER = 1;                // Enable UART0 RX 
  uint32_t dummy = U0IIR;   // Read IrqID - Required to Get Interrupts
Started
}

void UART::setBaudRate(uint32_t baudRate)
{
  uint32_t DLreload;
  //Hardcoded to 15 MHz PClk (VPBDIV = 0x0)
  DLreload = static_cast<uint32_t>((15000000u / baudRate) / 16u);
  
  U0LCR |= 0x80;           /* Set DLAB */
  U0DLL = DLreload;
  U0DLM = (DLreload >> 8);
  U0LCR &= ~0x80;          /* Clear DLAB */    
}

  void UART_ISR(void)
  {
   
    uint8_t interruptMask = U0LSR;  //Also resets interrupts in LSR
    
    uint8_t IIR = U0IIR;
    
    //Active low
    if((IIR & 0x1) == 0)
    {
      //Data ready in RxBuffer
      if((IIR & 0x04) != 0)
      {
        if(!(interruptMask & 0x01))
        {
          uint8_t byte = U0RBR;
          //Handle byte ......
        }
      }
    }

    // Acknowledge interrupt in VIC
    VICVectAddr = 0u; 
  }

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.