AnsweredAssumed Answered

Getting inverted data on RX when using uart 4

Question asked by Jesper Evertsson on Aug 17, 2016
Latest reply on Aug 18, 2016 by Daniel Chen

Hi, I'm trying to get rs232 to work on our custom hardware which uses the K60F120M cpu. For uart 4 we have TX = PTE24 and RX = PTE25. To get this to work I made the following change in our BSP in init_gpio.c:

 

case 4:

            pctl = (PORT_MemMapPtr)PORTE_BASE_PTR;

            if (flags & IO_PERIPHERAL_PIN_MUX_ENABLE)

            {

                pctl->PCR[24] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK; //TX

                pctl->PCR[25] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK; //RX      

            }

            if (flags & IO_PERIPHERAL_PIN_MUX_DISABLE)

            {

                pctl->PCR[24] = 0;

                pctl->PCR[25] = 0;

            }

            if (flags & IO_PERIPHERAL_CLOCK_ENABLE)

            {

                /* start SGI clock */

                sim->SCGC1 |= SIM_SCGC1_UART4_MASK;

            }

            if (flags & IO_PERIPHERAL_CLOCK_DISABLE)

            {

                /* stop SGI clock */

                sim->SCGC1 &= (~ SIM_SCGC1_UART4_MASK);

            }

            break;

 

I've then made a small example to test if it works:

 

  #define RS485_CHANNEL "ittye:"

 

  ...

 

   MQX_FILE_PTR rs485_dev = NULL;

   char  data_buffer[6] = {0};

   data_buffer[0] = 'H';

   data_buffer[1] = 'E';

   data_buffer[2] = 'L';

   data_buffer[3] = 'L';

   data_buffer[4] = 'O';

 

   rs485_dev  = fopen( RS485_CHANNEL, NULL );

   uint32_t baud = 19200;

   ioctl(rs485_dev, IO_IOCTL_SERIAL_SET_BAUD, &baud);

 

  write( rs485_dev, data_buffer, strlen(data_buffer) );

  fflush( rs485_dev );

 

What happens when I run this code is that what I send on the TX is also what I get on RX (but inverted) even though it isn't connected to anything else than the logic analyzer I use to meassure. So it seems that somehow, everything I send out I recieve an inverted copy of. How can I get rid of this behaviour? Did I do anything wrong when changing init_gpio.c?

 

Just to clarify, this is the result from my logic analyzer (where the top signal is tx and the bottom rx):

 

uart.PNG

Outcomes