HOW TO MAKE TWO SERIAL(UART) PORT IN FRDMK64F120

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

HOW TO MAKE TWO SERIAL(UART) PORT IN FRDMK64F120

Jump to solution
6,328 Views
sudhakarp
Contributor V

hi,

now i am working on frdmk64f120 controller. i need two serial port example code. i have "hello example" code but  its a OpenSDAv2 connection port.i need one more port using  some other RX and TX pin. can you give some example code..? its useful to me.

Labels (1)
0 Kudos
1 Solution
2,368 Views
DavidS
NXP Employee
NXP Employee

Hi Sudhakar,

There are several ways to implement another UART into the project but I will show how I did it be adding code to the eth_to_serial_frdmk64f project and into the KSDK source.

The attached files need to place added to your KSDK_1.1.0 path.

bsp.h and init.bsp.c go to:  C:\Freescale\KSDK_1.1.0\rtos\mqx\mqx\source\bsp

board.h goes to: C:\Freescale\KSDK_1.1.0\boards\frdmk64f

demo.c and config.h go to: C:\Freescale\KSDK_1.1.0\tcpip\rtcs\examples\eth_to_serial

Note: In config.h I have changed the network IP to work on my network.  Please adjust to work on your network.

Please backup your files before over writing.

Once you have pulled in the files from the ZIP, look for "//DES" to see where I added code and comments.

The demo now has UART4 on PTC14 and PTC14.  On my FRDM-K64F Freedom board I have jumpered J199 pins 3 and 4 to create a hardware loopback.  I'm using an O-Scope to monitor traffic.

When you run the demo, you should see an output on J199 during setup.  Once you use a Telnet client to connect to the FRDM-K64F board, when ever you type in the Telnet client, you will see output on J199.  I am only outputting to J199 from the Telnet client.  I am not doing anything with the UART RX because of the hardware loopback.

I think the code should get you going.

Regards,

David

View solution in original post

0 Kudos
23 Replies
2,231 Views
sudhakarp
Contributor V

Hi David,

     finally i achieved 2UART port. your code was working fine(ethernet_to_serial_UART4). i only did some mistake in my code.thank you very much.

     but DAVID if i transmit data continuously some character was missing how to avoid that one.and also any API function there to check DATA available on receive buffer or not.


and also can you explain what is

//  close(0);

    fd = open("ttye:", NIO_TTY_FLAGS_EOL_RN | NIO_TTY_FLAGS_ECHO);  // 0 - stdin

    assert(fd == 4);//4

//   close(1);

    fd = open("ttye:", NIO_TTY_FLAGS_EOL_RN | NIO_TTY_FLAGS_ECHO);  // 1 - stdout

    assert(fd == 6);//6

//   close(2);

    fd = open("ttye:", NIO_TTY_FLAGS_EOL_RN | NIO_TTY_FLAGS_ECHO);  // 2 - stderr

    assert(fd == 7);//7

      what is "4,6,7" argument value. explain close() and assert() function


regards,

sudhakar p

        

0 Kudos
2,231 Views
DavidS
NXP Employee
NXP Employee

Hi Sudhakar,

Glad you are up and running.

Please review a post that discusses implementing non-blocking UART call:

Re: KSDK 1.1.0 getchar() does not return EOF

With respect to the asserts, I merely copied and pasted the default code, then during debugging determined what the "fd" return value was and used it in the assert() function.

Regards,

David

2,231 Views
sudhakarp
Contributor V

Hi David,

  

     how to implement UART interrupt Transmit and receive mode. do you have any example code for this.i want to receive all data in interrupt routine only. so we can avoid data losing also.UART receive interrupt mode is more important. can you give any example code..?

thanks And Regards,

sudhakar p

0 Kudos
2,231 Views
DavidS
NXP Employee
NXP Employee

Hi Sudhakar,

Please review this post to see if it helps.

Re: Using KSDK for interrupt driven UART?

Regards,

David

0 Kudos
2,231 Views
sudhakarp
Contributor V

Hi David,

          i added fsl_uart_irq.c in my project. if  i press any character UART0_RX_TX_IRQHandler(void) function was

calling. but this function running continuouly how to avoid thaT PROBKEM

void UART0_RX_TX_IRQHandler(void)

{

    uint8_t sourceBuff[26] ="UART-1\t"; // sourceBuff can be filled out with desired data

    uint8_t readBuffer[10] = {0};

    printf("hello");

    //UART_DRV_ReceiveDataBlocking(0, readBuffer, 1,100);

    //UART_DRV_SendDataBlocking(0, readBuffer, 1,100);

  //  UART_DRV_IRQHandler(0);

}

0 Kudos
2,229 Views
DavidS
NXP Employee
NXP Employee

Hi Sudhakar,

Seems like you are very close.  That is good.

With your development environment (KDS+KSDK+MQX) are you also using PE (Processor Expert)?

If you set a breakpoint within the UART0_RX_TX_IRQHandler(), was it called from void UART_DRV_IRQHandler(uint32_t instance)() handler?

If not, then your software linkage needs work.

The UART0_RX_TX_IRQHandler() should have been registered as a callback function for your UART.  It receives the character(s) and clears the interrupt while doing it.  So if this call is missing I think that would explain your issue.

In my previously posted code when I used PE to help setup a callback the code looks like (from Cpu.c Components_Init() function):

    /*! uartBluetooth Auto initialization start */

    OSA_InstallIntHandler(UART4_RX_TX_IRQn, UART4_RX_TX_IRQHandler2);

    UART_DRV_Init(FSL_UARTBLUETOOTH,&uartBluetooth_State,&uartBluetooth_InitConfig0);

    UART_DRV_InstallRxCallback(FSL_UARTBLUETOOTH, uartBluetooth_RxCallback, g_rxBuff, NULL, true);

    NVIC_SetPriority(UART4_RX_TX_IRQn, 112U);

Regards,

David

0 Kudos
2,229 Views
sudhakarp
Contributor V

Hi David,

          i am not using any PE. In "init_bsp.c" FILE just  i added

"_int_install_isr(UART0_RX_TX_IRQn,(INT_ISR_FPTR)UART0_RX_TX_IRQHandler, NULL);"

this function inside of "int _bsp_init(void)" function. is this  enough for interrupt.?. i am using same default ether_to_serial example code only. but  UART0_RX_TX_IRQHandler() function was not called if i pressed any character from serial.

regards,

sudhakar p

0 Kudos
2,229 Views
sudhakarp
Contributor V

Hi David,

     i achieved interrupt UART Receive,Thanks a lot. just i called this API in my code

"_int_install_isr(UART4_RX_TX_IRQn,(INT_ISR_FPTR)UART4_RX_TX_IRQHandler, NULL);

      UART_DRV_InstallRxCallback(4,uartBluetooth_RxCallback,g_rxBuff, NULL, true);"  now  if i press any character this function was calling every time uartBluetooth_RxCallback().


     now i want to go next level. i need more support from you. next i want to implement RTS/CTS flow control can you give any idea...?

Thanks and regards,

sudhakar p

0 Kudos
2,229 Views
sudhakarp
Contributor V


Hi,

      i want to implement RTS/CTs flow control. do you have any example code..?

regards,

sudhakar p

0 Kudos
2,231 Views
sudhakarp
Contributor V

hi David & Mark,

               i feel bad myself. last 3week i am trying to implement Two UART port  with separate receive/transmit. but still i am struggling with this things. UART is a basic but i cant implement. please any one guide me. otherwise give proper example code for separate RX/TX for each uart-1 and uart-2.

     David or mark can you make code like, in one task i want to receive and echo same character from uart-1 and another task UART-2 port want to receive and echo that character. here there is no relationship between uart-1 and uart-2. Two ports are working independently.i think its easy for you so please do favor for me. i will make hardware part myself its not problem.just mention what are Pin's used  for UART port. it is useful to connect hardware RX/TX pin.

0 Kudos
2,231 Views
ivadorazinova
NXP Employee
NXP Employee

Hi sudhakar p,


no we have not the KSDK example.

But I can prepare this short example for you.


Best Regards,

Iva

0 Kudos
2,231 Views
sudhakarp
Contributor V

Hi iva,

               when i will get example code..? how much time you need to make code.? am waiting for your reply..

plz send as soon as possible...

0 Kudos
2,231 Views
ivadorazinova
NXP Employee
NXP Employee

Hi sudhakar,

yes - I created the example for you.

Please, look at the example here UART Example with KSDK

I hope it helps you,

Best Regards

Iva

2,231 Views
sudhakarp
Contributor V

Hi Iva,

i am happy with your reply. hardware part everything OK but i saw your example code. but inside main loop nothing is there.i think you did this things in some other files can you  highlight UART depended function and variables. please mention some basic UART initialization and configuration function. please guide step by step because i am new for this controller.

regards,

sudhakar p

0 Kudos
2,231 Views
sudhakarp
Contributor V

hi David,

          actually frdmk64 have 5UART.I want 4-UART to work. in example project they are using openSDA as a serial. and also they are using PTC16 and PTC17 pin. this is UART-3 RX and TX pin. am i correct.? but in example code i don't know how they are initializing that UART. so can you guide how to initialize UART RX/TX pins and how to  receive/transmit with interrupt it will useful to me.


if you give one example code using that example i will make 4-UART easily. please send example code like that.

regards,

sudhakar.p

0 Kudos
2,231 Views
DavidS
NXP Employee
NXP Employee
0 Kudos
2,231 Views
sudhakarp
Contributor V

Hi David,

I build your example project its working fine. sorry but its not useful to me. actually now i am editing Ethernet to serial code. in this project already i did 2client listen code.(port-23 and port-24). here i want to transfer port-23 client data to one serial(UART-1 or 2) port and port-24 client data to another serial(UART-3 or 4) port to avoid data collision. i think you will understand my problem.

          in ethernet to serial project tx_task and rx_task functions are there. Its using SDA serial port for transferring data from client . instead of SDA i want one more Serial port to transfer data from CLIENT-2 connection. Then only i can avoid data collision between 2 client connection. now can you guide how to make one more UART program in ethernet to serial project..?. i am waiting for your reply.

regards,

sudhakar.p

0 Kudos
2,369 Views
DavidS
NXP Employee
NXP Employee

Hi Sudhakar,

There are several ways to implement another UART into the project but I will show how I did it be adding code to the eth_to_serial_frdmk64f project and into the KSDK source.

The attached files need to place added to your KSDK_1.1.0 path.

bsp.h and init.bsp.c go to:  C:\Freescale\KSDK_1.1.0\rtos\mqx\mqx\source\bsp

board.h goes to: C:\Freescale\KSDK_1.1.0\boards\frdmk64f

demo.c and config.h go to: C:\Freescale\KSDK_1.1.0\tcpip\rtcs\examples\eth_to_serial

Note: In config.h I have changed the network IP to work on my network.  Please adjust to work on your network.

Please backup your files before over writing.

Once you have pulled in the files from the ZIP, look for "//DES" to see where I added code and comments.

The demo now has UART4 on PTC14 and PTC14.  On my FRDM-K64F Freedom board I have jumpered J199 pins 3 and 4 to create a hardware loopback.  I'm using an O-Scope to monitor traffic.

When you run the demo, you should see an output on J199 during setup.  Once you use a Telnet client to connect to the FRDM-K64F board, when ever you type in the Telnet client, you will see output on J199.  I am only outputting to J199 from the Telnet client.  I am not doing anything with the UART RX because of the hardware loopback.

I think the code should get you going.

Regards,

David

0 Kudos
2,231 Views
sudhakarp
Contributor V

Hi david,

     i dnt want to confuse you. i attached my code please just see and let me know what mistake i did. why both uart not working at a same time.

regards,

sudhakar p

Hi
0 Kudos
2,231 Views
M_Grillo
Contributor III

Hello David & sudhakar,

I’m trying to accomplish the same exact thing. You may see my questions in another thread. Documentation on the new “NIO” device drivers for MQX would be very helpful. MQX 4.x.x for Codewarrior was very straight forward with intuitive documentation. I think what sudhakar is looking for along with myself is a the new equivalent for MQX w/SDK of the old MQX example I wrote below for initializing two UART ports.

Mark

“NOTE! This example is for MQX 4.x  not SDK’s implementation of MQX.”

uint_32 Uart_setup()

{

       uint_32 error = 0;

      

          /* Setup serial port driver */

           serial_fd = fopen("ittyd:",0); //UART3 //Sets up file pointer to the Serial Port to drive <MG>

           ioctl(serial_fd, IO_IOCTL_SERIAL_SET_FLAGS, &ulFlags); //IO_SERIAL_NON_BLOCKING);//

           ulUART0_baud = 115200;

           error = _io_ioctl(serial_fd, IO_IOCTL_SERIAL_SET_BAUD, &ulUART0_baud);      //Change/set Baud Rate from default to "Baud_rate"

        

          /* Setup 2nd serial port driver */

           serial_fd2 =  fopen("ittye:", 0); //UART4 //Sets up file pointer to the 2nd <debug> Serial Port <MG>

           ioctl(serial_fd2, IO_IOCTL_SERIAL_SET_FLAGS, &ulFlags);

           error = _io_ioctl(serial_fd2, IO_IOCTL_SERIAL_SET_BAUD, &ulUART0_baud);      //Change/set Baud Rate from default to "Baud_rate"

}

0 Kudos