This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

netInitialize() hang ...

Hi
I just want to make a TCP socket connection. I configure everything as the "Creating a Network Application" page tell.

as system start to debug or work it halts on netInitialize(). even the codes before this function doesn't work.

would you please help me on this ?

#include "rl_net.h"
#include "GPIO_LPC17xx.h"
int32_t tcp_sock;                       // TCP socket handle

uint32_t tcp_cb_client (int32_t socket, netTCP_Event event, const NET_ADDR *addr, const uint8_t *buf, uint32_t len);
void send_data (void);

 int main(void)
{
        // Allocate and initialize the socket.
  GPIO_SetDir (2, 1, GPIO_DIR_OUTPUT);


                GPIO_PinWrite (2, 1, 0); // LED on: set port

 netInitialize ();

                GPIO_PinWrite (2, 1, 1); // LED on: set port

  // Allocate a free TCP socket.
  tcp_sock = netTCP_GetSocket (tcp_cb_client);

        while(1);
}
// Notify the user application about TCP socket events.
uint32_t tcp_cb_client (int32_t socket, netTCP_Event event,
                        const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {

  switch (event) {
    case netTCP_EventConnect:
      // Connect request received
      break;

    case netTCP_EventEstablished:
      // Connection established
      break;

    case netTCP_EventClosed:
      // Connection was properly closed
      break;

    case netTCP_EventAborted:
      // Connection is for some reason aborted
      break;

    case netTCP_EventACK:
      // Previously sent data acknowledged
      break;

    case netTCP_EventData:
      // Data received
      break;
  }
  return (0);
}

// Connect to TCP server and send data.
void send_data (void) {
  // IPv4 address: 192.168.0.1
  NET_ADDR addr = { NET_ADDR_IP4, 2000,
                    192, 168, 0, 1 };
  // IPv6 address: [fe80::1c30:6cff:fea2:455e]
//NET_ADDR addr = { NET_ADDR_IP6, 2000,
//                  0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//                  0x1c, 0x30, 0x6c, 0xff, 0xfe, 0xa2, 0x45, 0x5e };

  if (tcp_sock > 0) {
    switch (netTCP_GetState (tcp_sock)) {
      case netTCP_StateUNUSED:
      case netTCP_StateCLOSED:
        // Connect to TCP socket server on port 2000
        netTCP_Connect (tcp_sock, &addr, 0);
        break;

      case netTCP_StateESTABLISHED:
        // Connected, send the data
        if (netTCP_SendReady (tcp_sock) == true) {
          /* Example
          uint8_t *sendbuf;

          sendbuf = netTCP_GetBuffer (2);
          sendbuf[0] = 0x01;
          sendbuf[1] = 0x55;

          netTCP_Send (tcp_sock, sendbuf, 2);
          */
        }
        break;

      default:
        break;
    }
  }
}


  • What do you mean with:
    "work it halts on netInitialize()"
    When you single step through your code, does netInitialize() not return or to you run on an exception?

    "even the codes before this function doesn't work"
    Does the code before 'netInitialize()' work if you remove 'netInitialize'. In any case, I guess your project is not configured the right way. Did you try one of our examples on your board (MCB1700, LPCXpresso etc.)? You could copy the project setup from one of those examples.