LPC2129 UART ISR Problem

I'm using the LPC2129 and Keil Tools. The purpose of the code is to interrupt on the receipt of a single byte of data and assign "data" to its value. The interrupt seems to work however "data" isn't the right value. Please help, Thanks.

#include <stdio.h> /* prototype declarations for I/O functions */
#include <lpc21xx.h> /* LPC21xx definitions */

void U1ISR(void) __irq; //Declare UART1 IRQ ISR

int data;

int main (void) {

PINSEL0 = 0x0005800A; // Enable UART1

U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 8; /* 115200 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
U1IER = 0x1; //Enable the RDA interrupt

VICVectAddr0 = (unsigned long)U1ISR; //Set UART1 ISR Vector Address
VICVectCntl0 = 0x20 | 7; //Enable Slot, Set Channel 7
VICIntEnable = 0x80; //Enable Int UART1

blah ... blah ... blah

while (1) {

yada ... yada ... yada

}

}

void U1ISR(void) __irq {

U1IIR |= 0x01; /* Clear Interrupt */

data = U1RBR;

VICVectAddr = 0x0; /* return from interrupt */

}

Parents
  • Hi, I cut/copied your code and have run it on Keil in the simulator mode. used serial#2 window and looked at Uart1, whatever character I type appears in the U1RBR/THR window correctly. ie. 1 = 0x31, Q=0x51 etc

    I have not tried on a target because I have to switch to uart0. I can do it but see if you can get the same simulation to work.

    Then I have a request to you. Would you mind looking at my post of today. Download the example and explain to me whats going on. I kept going back to it on and off all day. But I am too inexperienced with C to know what to do. Thanks!

    Further, I have just played with your code, it compiles fine in Thumb mode, but throws a link error in ARM mode. Is there something that I have to do in the C code other than just switch the target options between Thumb/Arm ?

    Greatly appreciate some help.

    #include <stdio.h> /* prototype declarations for I/O functions */
    #include <lpc21xx.h> /* LPC21xx definitions */

    void U1ISR(void) __irq; //Declare UART1 IRQ ISR

    int data;

    void main (void)

    {
    PINSEL0 = 0x0005800A; // Enable UART1
    U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
    U1DLL = 8; /* 115200 Baud Rate @ 15MHz VPB Clock */
    U1LCR = 0x03; /* DLAB = 0 */
    U1IER = 0x1; //Enable the RDA interrupt

    VICVectAddr0 = (unsigned long)U1ISR; //Set UART1 ISR Vector Address
    VICVectCntl0 = 0x20 | 7; //Enable Slot, Set Channel 7
    VICIntEnable = 0x80; //Enable Int UART1
    U1FCR = 0x07; //Enables and Resets FIFO, 1 byte

    while (1) { }
    }

    void U1ISR(void) __irq { U1IIR |= 0x01; /* Clear Interrupt */ data = U1RBR; VICVectAddr = 0x0; /* return from interrupt */
    }

Reply
  • Hi, I cut/copied your code and have run it on Keil in the simulator mode. used serial#2 window and looked at Uart1, whatever character I type appears in the U1RBR/THR window correctly. ie. 1 = 0x31, Q=0x51 etc

    I have not tried on a target because I have to switch to uart0. I can do it but see if you can get the same simulation to work.

    Then I have a request to you. Would you mind looking at my post of today. Download the example and explain to me whats going on. I kept going back to it on and off all day. But I am too inexperienced with C to know what to do. Thanks!

    Further, I have just played with your code, it compiles fine in Thumb mode, but throws a link error in ARM mode. Is there something that I have to do in the C code other than just switch the target options between Thumb/Arm ?

    Greatly appreciate some help.

    #include <stdio.h> /* prototype declarations for I/O functions */
    #include <lpc21xx.h> /* LPC21xx definitions */

    void U1ISR(void) __irq; //Declare UART1 IRQ ISR

    int data;

    void main (void)

    {
    PINSEL0 = 0x0005800A; // Enable UART1
    U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
    U1DLL = 8; /* 115200 Baud Rate @ 15MHz VPB Clock */
    U1LCR = 0x03; /* DLAB = 0 */
    U1IER = 0x1; //Enable the RDA interrupt

    VICVectAddr0 = (unsigned long)U1ISR; //Set UART1 ISR Vector Address
    VICVectCntl0 = 0x20 | 7; //Enable Slot, Set Channel 7
    VICIntEnable = 0x80; //Enable Int UART1
    U1FCR = 0x07; //Enables and Resets FIFO, 1 byte

    while (1) { }
    }

    void U1ISR(void) __irq { U1IIR |= 0x01; /* Clear Interrupt */ data = U1RBR; VICVectAddr = 0x0; /* return from interrupt */
    }

Children
More questions in this forum