Page 1 of 1

lib_uart uart_rx.xc bug?

Posted: Mon Aug 14, 2017 3:20 pm
by akp
Hi,

I found when I am inputting a break (i.e. uart input stuck at zero) with the uart_rx.xc the code outputs continuous 0x00 bytes, even though there is no stop bit -> start bit transition. I believe that is due to the INPUTTING_STOP_BIT state not functioning correctly. I think it may arise in situations where stop_bits is set to 1 (probably the most common situation I would imagine). Here is the existing code:

Code: Select all

      case INPUTTING_STOP_BIT:
        int level_test = p_rxd.input();
        if (level_test == 0) {
          p_rxd.event_when_pins_eq(1);
          state = WAITING_FOR_HIGH;
        }
        stop_bit_count--;
        t += bit_time;
        if (stop_bit_count == 0) {
          p_rxd.event_when_pins_eq(0);
          state = WAITING_FOR_INPUT;
        }
        break;
I have changed it as follows and it seems to work better (i.e. not returning continuous 0x00 bytes in stuck at zero line state but still returning expected data in normal line state):

Code: Select all

      case INPUTTING_STOP_BIT:
        int level_test = p_rxd.input();
        if (level_test == 0) {
          p_rxd.event_when_pins_eq(1);
          state = WAITING_FOR_HIGH;
        }
        else {
          stop_bit_count--;
          t += bit_time;
          if (stop_bit_count == 0) {
            p_rxd.event_when_pins_eq(0);
            state = WAITING_FOR_INPUT;
          }
        }
        break;

Re: lib_uart uart_rx.xc bug?

Posted: Wed Aug 23, 2017 10:53 pm
by andrewxcav
I agree that one stop bit is going to be the most likely (only?) use case. It looks like your fix would work for multiple stop bits as well.

Can you submit a pull request to GitHub?