MATLAB Examples

Exchanging Ethernet Data with the FRDM K64F hardware

This example shows you how to use Simulink Coder Support Package for NXP FRDM-K64F Board to send and receive UDP data.



In this example you will learn how to use UDP Send and UDP Receive blocks to send and receive Ethernet data with the FRDM K64F board.

The Ethernet port on the FRDM K64F board supports the IEEE 802.3 standard.


We recommend completing the Getting Started with Simulink Coder Support Package for NXP FRDM-K64F Board.

Required Hardware

To run this example, you will need the following hardware:

  • NXP FRDM-K64F Board
  • USB type A to Micro-B cable
  • RJ45 Ethernet cable.
  • Optional router for automatic IP assignment.

The FRDM-K64F Board provides an Ethernet port. This port can be used for data communication using the lwIP TCP/IP stack provided by NXP KSDK.

Hardware and Network Configuration

In this task you will configure the hardware and network properties needed to run this example.

  • The default Configuration of the target model present in this example are configured to get an IP address at startup using DHCP. This workflow is compatible when both the host computer and the target hardware are connected to a router. If you wish to connect the board straight into your host computer with the Ethernet cable, assign the FRDM-K64F board with a static IP address. The Ethernet settings are located in the Configuration Parameters of the model under Hardware Implementation -> Target Hardware Resources -> Ethernet. To choose a static IP address, uncheck the Enable DHCP for IP address assignment. This will prompt you to enter the static IP and subnet mask. Ensure that the IP address and subnet mask are unique and appropriate.

Settings for Automatic IP Address Assignment using DHCP:

  • Connect the FRDM-K64F board with a network cable to a router for automatic IP address assignment. In this configuration, the host computer also needs to be connected to the same router. This can be done with a network cable or over WiFi.

Ethernet Settings for Static IP Address Assignment:

  • Connect the FRDM-K64F board with a network cable to the host computer. In this configuration, set the FRDM-K64F board with a static IP address.

Task 1 - UDP Communication between the Target and the Host Computer

In this task, you will run the Fault Tolerant Fuel Control System Example on the FRDM-K64F board. The control algorithm runs on the target while the host runs a plant simulation of the system. The target and the host communicate via UDP. The target model receives the fuel system control sensors values from the host model and transmits back the calculated fuel mixture ratio to the host computer.

Models Involved in this Example

1. UDP Target Model

2. UDP Host model

Run the Model configured for the target on the hardware

1. Open the UDP target model. This model has been configured for NXP FRDM-K64F.

2. Configure the network properties for the model as described in the previous task: Hardware and Network Configuration.

  • On the target UDP Send block, the remote IP port has to match the local IP port of the host model UDP Receive block.
  • On the target UDP Receive block, the local IP port has to match the remote IP port of the host model UDP Send block.

3. The UDP Send and Receive blocks on the target model are configured to do a transmit broadcast and receive from all IP address in the subnet. You can change this to send to a specific IP address if you know the IP address of the host computer.

4. On the UDP target model, press Ctrl+B or click on the Deploy to Hardware button to build, load and run the model on the target.

Run the Host Model and analyze the data

1. The UDP Send block on the UDP Host model is configured to transmit to the Target IP address ''. You may have to change this to send to the IP address of your target board NXP FRDM-K64F.

2. While the target model is running, run the UDP Host model to send simulated sensor data to the target and visualize the calculated response by the controller.


This example showed how to program your NXP FRDM-K64F board to configure and exchange data between Host and the target via Ethernet Communication. In this example you learned how to:

  • Communicate with Host PC via Ethernet.
  • Program the NXP FRDM-K64F board to send and receive ethernet data from specific ports.