AnsweredAssumed Answered

MQX Vybrid Serial communication error

Question asked by n00b1024 on Feb 5, 2014
Latest reply on Feb 10, 2014 by n00b1024



I'm having a bit of a problem with the serial communication on the Vybrid. I can write from the UART on the Vybrid fine, but it has trouble receiving data correctly. I've been sending data from a couple different terminal emulators (one of them being TeraTerm). Code below, using MQX 4.0.2, VF60GS10, IAR EWARM:


  pointer old_handle, fh_ptr, statptr;

  boolean disable_rx = FALSE;

  uint_32 baud = 9600;

  uint_32 result;   

  uint_32 ser_opts = IO_SERIAL_NON_BLOCKING;

  fh_ptr = (pointer)fopen("ttyb:", BSP_DEFAULT_IO_OPEN_MODE);

  result = ioctl(fh_ptr, IO_IOCTL_SERIAL_SET_FLAGS, &ser_opts);

  result = ioctl(fh_ptr, IO_IOCTL_SERIAL_DISABLE_RX, &disable_rx );

  result = ioctl(fh_ptr, IO_IOCTL_SERIAL_SET_BAUD, &baud);


  if (fh_ptr == NULL) {                                                 //if no driver, driver not working

    printf("Cannot open IO device\n");

  } else {                                                              //if driver works

    old_handle = _io_set_handle(IO_STDOUT, fh_ptr);                     //changing the address of the IO handle IO_STDOUT to that pointed to by fh_ptr



  _mqx_int bytes_written;

  char tx_data_buffer[] = "abc";


    char rx_data_buffer[16] = "";

    //    char num_bytes_written =    write(stdout, tx_data_buffer, strlen(tx_data_buffer));

    char num_bytes_read = read( stdout, rx_data_buffer, 16);



Often, the Vybrid doesn't recognize all the bytes that the terminal emulator sends: num_bytes_read and UART1_RCFIFO (before read) are smaller than the number of characters originally sent. Other times, the Vybrid can recognize that X characters were sent, but thinks that they're all zero. Sometimes, the processor receives all the characters correctly, but will have them slightly out of order (e.g. displays "2345678abcdef01" in rx_data_buffer instead of "12345678abcdef0"). I've tried changing the buffer size and gotten different (but not consistently correct) results. I've also tried switching off non-blocking mode, but had odd results when doing that. Thoughts?