MQX Vybrid Serial communication error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MQX Vybrid Serial communication error

1,294 Views
n00b1024
Contributor III

Hi,

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);

  fflush(fh_ptr);

  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

  }

  fflush(stdout);

  _mqx_int bytes_written;

  char tx_data_buffer[] = "abc";

  while(1){  

    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?

Labels (2)
0 Kudos
5 Replies

613 Views
n00b1024
Contributor III

Hi Rene,

Thanks for the advice. I'm using the debug port deliberately, and have switched my jumper settings depending on whether I was to use the debug port or the serial connector on the TWR-SER. I fixed the problem with reading by cutting out most of the MQX reading function and tweaking my code to reading the data register on the Vybrid, as below.

  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(RS232_CHANNEL, 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); 

  char i = 0;

  char rx_data_buffer[3];                                         //can also be done with a 16-char buffer

    if (!(UART1_SFIFO & 0x40)){                                         //if the rx buffer isn't empty

      while(i<3){ 

        rx_data_buffer[i] = UART1_D;

        i++;

      }

      i = 0;

      UART1_CFIFO |= 0x40;      //flushing the RXFIFO

      memset(rx_data_buffer,0,sizeof(rx_data_buffer));                    //reset the array to zero

    }

0 Kudos

613 Views
rendy
NXP Employee
NXP Employee

Hi,

I have used your code sample and saw similar results. I expect the problem is that you are opening 'ttyb:' which is by default assigned to STDOUT/STDIN on Vybrid Tower module. Please see my code snippet, it reads data from TWR-SER2 serial and prints them to OpenSDA virtual port (or vice versa, depending on your J23 and J24 setting). Works well for me.

FILE * sci2;

char buffer[16] = "";

uint_32 baud = 115200;

uint_32 br = 0;

sci2 = fopen("ttyc:","");

ioctl(sci2, IO_IOCTL_SERIAL_SET_BAUD, &baud);

while(1)

{

    br = read( sci2, buffer, 15);

    buffer[br+1] = '\0';

    printf("%s\n", buffer);

}

Rene

0 Kudos

613 Views
billpringlemeir
Contributor V

Do you use the USB to serial connection via the OpenSDA debug port or the direct serial via the DB9 connector?  There are issues with the USB serial.  Set very tiny jumpers at the 'white' connector side midway to be parallel to the connector.  They are J23 and J24.  The OpenSDA debugger definitely has issues.

0 Kudos

613 Views
n00b1024
Contributor III

Bill,

I've been using the OpenSDA debugger so far, and managed to fix my problem, but it's a relief to hear that other people have been having problems with it.

0 Kudos

613 Views
n00b1024
Contributor III

I've also tried working outside of the MQX driver, setting up the UART according to the registers pictured below. When I try to read the UART1_D register inside an infinite while loop, it'll skip received characters. For example, if I send the string "12345", I might get "1", "3", "4" during consecutive reads of UART1_D. I also ran the program on another VF60GS10 board and had the same issues, so it's not due to electrical damage to the board.

uart1_default.png

0 Kudos