Skip to main content
Visitor II
October 13, 2003
Question

USART interrupt not working

  • October 13, 2003
  • 4 replies
  • 1095 views
Posted on October 13, 2003 at 10:57

USART interrupt not working

    This topic has been closed for replies.

    4 replies

    mike3Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:55

    Hey,

    I have Serial Port 0 working fine (receiving and transmitting), but now I want to use an interrupt triggered routing for receiving data.

    I can't get the program to run the correct ISR to clear the RI bit.

    Here's my code to set up the interrupt:

    PS = 1; /* set high priority for USART */

    ES = 1; /* enable USART 0 interrupt */

    EA = 1; /* enable interrupts */

    Here's my code for the ISR routine:

    static void USART_isr (void) interrupt SIO_VECTOR using 2

    {

    unsigned char temp;

    if (RI) //If Receive buffer is full

    {

    temp = (SBUF); //Retrieve Buffer

    RI = 0; //set RI bit to 0

    }

    }

    very simple code, but can't seem to get it go to the ISR.

    Any suggestions, comments??

    Thanks,

    Mike
    mike3Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:55

    Thanks, for the reply

    Interrupt initialization:

    void Interrupt_init (void)

    {

    EA = 0; /* disable interrupts */

    timer0_tick = 0;

    TR0 = 0; /* stop timer 0 */

    TMOD &= 0xF0; /* clear timer 0 mode bits - bottom 4 bits */

    TMOD |= 0x01; /* put timer 0 into 16-bit no prescale */

    // Calculate timer tollover based on FREQ_OSC to be 10ms periods

    timer0_value = 0x10000 - ( ((FREQ_OSC * 5L) / 6L) - 17L);

    TL0 = (timer0_value & 0x00FF);

    TH0 = (timer0_value >>

    ;

    PT0 = 1; /* set high priority for timer 0 */

    ET0 = 1; /* enable timer 0 interrupt */

    TR0 = 1; /* start timer 0 */

    PS = 1; /* set high priority for USART */

    ES = 1; /* enable USART 0 interrupt */

    EA = 1; /* enable interrupts */

    }

    No interrup is being generated on transmit. I only want an interrupt to be generated on receive.

    void Serial_Transmit(unsigned char value)

    {

    unsigned int clock_buf;

    //Disable Interrupts

    EA = 0;

    //Enable RTS signal

    P4_3 = TRUE;

    SBUF = value; // Xmit the Char

    while (TI == 0); // Wait Loop till finished xmit of last char

    TI = 0; //set TI bit to 0

    //extend the RTS signal to include the stop bit

    for (clock_buf=0; clock_buf

    {

    clock_buf++;

    }

    //Disable RTS signal

    P4_3 = FALSE;

    //Enable Interrupts

    EA = 1;

    }

    mike3Author
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:55

    Oh, sorry,

    SCON is set to 0x50

    Serial receive and trasmit works perfect, if I disable the interrupts.

    Timer 2 is used for baud rate generation, buad rate is perfect at 19200.

    Timer 0 is used for something else, and also calls interrupts.

    I'm having a hard time with this one.

    If I manually clear the RI bit, I'm fine, but I need it to generate an interrupt on receive and go to the ISR so I can clear the RI bit that way.
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 11:55

    Viper21,

    This is a crazy idea, but I don't see anything wrong with your code. The only thing I don't see is the #define for SIO_VECTOR. If you're using Keil C and the first USART, this should be defined as 4. Otherwise, you might be setting up an ISR for the other USART.

    Best Regards,

    Phaze