Possible issue with lib_uart Topic is solved

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
malo
Active Member
Posts: 33
Joined: Fri Sep 16, 2016 9:03 pm
Contact:

Possible issue with lib_uart

Postby malo » Wed Jul 18, 2018 4:29 pm

There is fragment of code in uart library to wait for stop bit

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;
      }
      break;


In the case when level_test is 0 - event is set to wait for 1 and with one stop bit the second event is set to wait for 0 in state WAITING_FOR_INPUT - no real wait for hi (stop bit)
It causes the problem in the case that there is just single one to zero (start bit) transition at the input which causes library to read bits until zero to one transition.

Is it intended?

wbr
malo
View Solution
mbruno
Posts: 3
Joined: Thu Aug 24, 2017 2:48 pm

Postby mbruno » Thu Jul 19, 2018 2:53 pm

malo,

Are you actually seeing this problem in hardware, or are you speculating that this might happen given the code?

I see what you are saying, and it does look incorrect to me. However, the first case where the input is still zero should never happen when things are working correctly as a stop bit is required at this point. In this case it just needs to recover and look for a new start bit, which ultimately I think it does. Perhaps it would be better for the second half of the INPUTTING_STOP_BIT case to be in an else:

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;


Mike
malo
Active Member
Posts: 33
Joined: Fri Sep 16, 2016 9:03 pm
Contact:

Postby malo » Thu Jul 19, 2018 4:06 pm

Hello Mike,

thanks for your answer.
it causes problem when usb cable is disconnected from the USB to UART IC connected to xmos uart rx pin and rx voltage level goes from hi to low - which is recognised as start bit by lib_uart and loads entire core with false data_ready () events:)

wbr
malo
mbruno
Posts: 3
Joined: Thu Aug 24, 2017 2:48 pm

Postby mbruno » Thu Jul 19, 2018 9:00 pm

malo,

I see, that makes sense. When the UART transmitter is idle it really should output a constant high rather than low. Is this your own hardware or an XMOS eval kit? Perhaps the RX line needs a pullup resistor.

That said, I *think* modifying the code to have an else as I shared in my previous post should fix your problem. Can you try that and let me know? If it does fix the issue I will submit a bug request to have the change made.

Thanks,
Mike
malo
Active Member
Posts: 33
Joined: Fri Sep 16, 2016 9:03 pm
Contact:

Postby malo » Fri Jul 20, 2018 3:26 pm

Hello Mike,

yes proposed fix works for me - thanks.

wbr
malo

Who is online

Users browsing this forum: No registered users and 51 guests