This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problems with UART_interrupt

The problem is when I start the uart_interrupt to get user input from keyboard, I found that the web server will be slow down and even stop echoing our request. If I disable the uart_interrupt, the web server works well again. It is strange that I didn't do anything special in our UART ISR.

Hopes you can help me

void uart_interrupt (void) small interrupt 4 using 0
/* ------------------------------------------------------------------------ --
* Purpose : Interrupt function. Save received char in buffer.
* Remarks : interrupt "4": seriel port interrupt, using cpu internal mem. bank "2"

* Restrictions:
* See also :
* Example :
* ************************************************************************ */
{
unsigned char ch;
int i;
// GPIO_LED = 0;//Light on LED
P3RxD = 1; //Force pull high //<<<<<<
ES = 0;
EA = 0;
if (RI) {/**************** Second problem ******************/
RI = 0;
/* save any framing error */
if (SM0) {
// uart_framing_error = TRUE;
SM0 = 0;
}
ch = SBUF;
rx_buf[rx_head] = ch;//save into ring buffer
rx_head = (rx_head + 1) & (RX_BUF_SIZE - 1);
}
P3TxD = 1; //Force pull high //<<<<<<
EA = 1;
ES = 1;
}

Parents
  • Hi,

    There are a couple of things i don't understand about your code:-

    1. Is P3RxD trying to set P3.0 the receive pin high and if so why as it is an input not an output?

    2. I dont understand why you are testing SM0 and resetting it as it is used to control (along with SM1 and SM2) the operating mode of the serial port, so i would normally expect it to be set as part of the serial port initialisation as i wouldnt expect the format of the received data to change. If this is necessary have you checked that it is being changed (outside the interrupt) when there is no serial activity?

    3. Unless you have any high priority interrupt (IP) bits set, I dont think you need 'ES=0;' or the 'EA=0;' as no other interrupts can occur whilst in this one.

    You could also be lining your self up for trouble in the line 'rx_head = (rx_head +1) & RX_BUF_SIZE -1);' as this relies upon RX_BUF_SIZE being 2^n and you would be better off using 'rx_head = (rx_head+1) % RX_BUF_SIZE;'

    You talk about echoing the data - does this mean your application also transmits the data in which case is it that it is getting into this interrupt routine because you are not testing and clearing TI?

    Mark.

Reply
  • Hi,

    There are a couple of things i don't understand about your code:-

    1. Is P3RxD trying to set P3.0 the receive pin high and if so why as it is an input not an output?

    2. I dont understand why you are testing SM0 and resetting it as it is used to control (along with SM1 and SM2) the operating mode of the serial port, so i would normally expect it to be set as part of the serial port initialisation as i wouldnt expect the format of the received data to change. If this is necessary have you checked that it is being changed (outside the interrupt) when there is no serial activity?

    3. Unless you have any high priority interrupt (IP) bits set, I dont think you need 'ES=0;' or the 'EA=0;' as no other interrupts can occur whilst in this one.

    You could also be lining your self up for trouble in the line 'rx_head = (rx_head +1) & RX_BUF_SIZE -1);' as this relies upon RX_BUF_SIZE being 2^n and you would be better off using 'rx_head = (rx_head+1) % RX_BUF_SIZE;'

    You talk about echoing the data - does this mean your application also transmits the data in which case is it that it is getting into this interrupt routine because you are not testing and clearing TI?

    Mark.

Children
No data