Sending data from ethernet in FRDMK64F?

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

Sending data from ethernet in FRDMK64F?

845 Views
mehmetak
Contributor I


Hello,

 

I have FRDK64F microcontroller. I would like to send a data from ethernet when I get the data from RS485. how can I do? Is there sample code or sending data from ethernet? Also, is my rs 485 code correct?

 

My rs485 code is here;

 

uint8_t command_t,command_2_1,command_2_2,command_2_3,byte0,byte1,byte2,byte3;

uint8_t receiveState=0;

uint8_t byteCounter=0;

uint8_t command=0;

uint8_t dataLength=0;

uint8_t checksum=0;

uint8_t calculatedChecksum;

uint8_t messageReceivedFlag=0;

uint8_t addresAndMessageType=0;

uint8_t sourceAddress[3];

uint8_t destinationAddress[3];

uint8_t receiveBuffer[50];

 

 

int main(void)

{

    uart_config_t config;

 

 

    BOARD_InitPins();

    BOARD_BootClockRUN();

 

 

    /*

     * config.baudRate_Bps = 115200U;

     * config.parityMode = kUART_ParityDisabled;

     * config.stopBitCount = kUART_OneStopBit;

     * config.txFifoWatermark = 0;

     * config.rxFifoWatermark = 1;

     * config.enableTx = false;

     * config.enableRx = false;

     */

    UART_GetDefaultConfig(&config);

    config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;

    config.enableTx = true;

    config.enableRx = true;

 

 

    UART_Init(DEMO_UART, &config, CLOCK_GetFreq(DEMO_UART_CLKSRC));

 

 

    /* Send g_tipString out. */

    UART_WriteBlocking(DEMO_UART, g_tipString, sizeof(g_tipString) / sizeof(g_tipString[0]));

 

 

    /* Enable RX interrupt. */

    UART_EnableInterrupts(DEMO_UART, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable);

    EnableIRQ(DEMO_UART_IRQn);

 

 

    while (1)

    {

  if(messageReceivedFlag) // Ben ekledimm.

  {

  command_t=command;

  command_2_1 = receiveBuffer[0];

  command_2_2 = receiveBuffer[1];

  command_2_3 = receiveBuffer[2];

  byte0 = receiveBuffer[3];

  byte1 = receiveBuffer[4];

  byte2 = receiveBuffer[5];

  byte3 = receiveBuffer[6];

  messageReceivedFlag=0;

  if(command_t==0xf4 && command_2_1==0x52 && command_2_2==0x42 && command_2_3==0x53)

  {

 

  }

  }

 

void DEMO_UART_IRQHandler(void)

{

    uint8_t data;

 

 

    /* If new data arrived. */

    if ((kUART_RxDataRegFullFlag | kUART_RxOverrunFlag) & UART_GetStatusFlags(DEMO_UART))

    {

        data = UART_ReadByte(DEMO_UART);

        switch(receiveState)

        {

            case 0:

                if(data==0x00)        // local address and message type(2) check

                {

                   addresAndMessageType=0;

                   calculatedChecksum=0;

                   receiveState=1;

                }

            break;

 

 

            case 1:         // Get source address

                sourceAddress[byteCounter++]=data;

                calculatedChecksum += data;

                if(byteCounter==3)

                {

                   receiveState=2;

                   byteCounter=0;

                }

            break;

 

 

            case 2:          // Get destination address

                destinationAddress[byteCounter++]=data;

                calculatedChecksum += data;

                if(byteCounter==3)

                {

                   receiveState=3;

                   byteCounter=0;

                }

            break;

 

 

            case 3:     // Get command

                command=data;

                calculatedChecksum += data;

                receiveState=4;

            break;

 

 

            case 4:     // Get packet lentgh

                dataLength=data;

                calculatedChecksum += data;

                byteCounter=0;

                receiveState=5;

            break;

 

 

            case 5:     // Get rest of the packet

            receiveBuffer[byteCounter++]=data;

                calculatedChecksum += data;

                if(byteCounter==dataLength)

                {

                    receiveState=6;

                }

            break;

 

 

            case 6:     // Get checksum and check it

                checksum=data;

                calculatedChecksum += data;

                if(calculatedChecksum == 0xff)

                {

                    messageReceivedFlag=1;

                }

                receiveState=0;

            break;

 

 

        }

    }

}

Labels (1)
0 Kudos
Reply
1 Reply

457 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Mehmet,

Regarding your  question, I suggest you download the SDK2.0 for FRDM-K64F from the website:

Welcome to Kinetis Expert | Kinetis Expert

After you download SDK2.0, you can find the lwip example code located at the directory:

C:\DriverE\Freescale\SDK2.0_K64F\boards\frdmk64f\demo_apps\lwip

We have echo example for both UDP and TCP protocol, if you use the K64 ethernet in client mode, I suppose you have to change the code, because the example is in server mode.

Regarding RS232, we have the UART driver located at :

C:\DriverE\Freescale\SDK2.0_K64F\boards\frdmk64f\driver_examples\uart

Regarding your UART code, I think it is okay.

BR

XiangJun Rong

0 Kudos
Reply