CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC24FJ256GB106 receives TCP data wrong

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
salihonur



Joined: 21 Mar 2020
Posts: 22

View user's profile Send private message

PIC24FJ256GB106 receives TCP data wrong
PostPosted: Tue Dec 07, 2021 5:23 pm     Reply with quote

Hi guys,

I'm having a problem receiving TCP data on PIC24FJ256. However, Modbus TCP works fine. TCP data comes with strange data in 16 bits.

Transmitting data size is 19 bytes, allocated buffer in PIC 32 bytes.

Please help me to solve this issue.

Transmitting data from the client:
Code:

[tcp]  Tx Data >> 21 AA BB 00 01 01 09 00 00 53 61 6C 69 68 4F 6E 75 72 59 20
[TCP] Package size: 19 bytes


Receiving data (PIC24FJ):
Code:

{tcp] RX << AA21 BB 11 09 530 6C61 6869 6E4F 7275 2059 00 00 00 00 00 00 14 20 6374 5D70 5220 2058 3C3C 20 16CA 16AA 00 00 00 00 00 00


TCP/IP configuration:
Code:

#define TCP_ETH_RAM_SIZE (STACK_CCS_SMTP_TX_SIZE + \
                          STACK_CCS_SMTP_RX_SIZE + \
                          STACK_CCS_HTTP2_SERVER_TX_SIZE + \
                          STACK_CCS_HTTP2_SERVER_RX_SIZE + \
                          STACK_MY_TELNET_SERVER_TX_SIZE + \
                          STACK_MY_TELNET_SERVER_RX_SIZE + \
                          STACK_MY_HTTPC_TX_SIZE + \
                          STACK_MY_HTTPC_RX_SIZE + \
                          1500)                        // 100*TCP_CONFIGURATION)

#if TCP_CONFIGURATION > 0
   TCPSocketInitializer_t TCPSocketInitializer[TCP_CONFIGURATION] =
   {
      #if defined(STACK_USE_CCS_HTTP2_SERVER)
         {TCP_PURPOSE_HTTP_SERVER, TCP_ETH_RAM, STACK_CCS_HTTP2_SERVER_TX_SIZE, STACK_CCS_HTTP2_SERVER_RX_SIZE},
      #endif
      #if defined(STACK_USE_SMTP_CLIENT)
         {TCP_PURPOSE_DEFAULT, TCP_ETH_RAM, STACK_CCS_SMTP_TX_SIZE, STACK_CCS_SMTP_RX_SIZE},
      #endif
      #if defined(STACK_USE_MY_TELNET_SERVER)
         {TCP_PURPOSE_TELNET, TCP_ETH_RAM, STACK_MY_TELNET_SERVER_TX_SIZE, STACK_MY_TELNET_SERVER_RX_SIZE},
      #endif
      #if defined(STACK_USE_CCS_HTTP_CLIENT)
         {TCP_PURPOSE_GENERIC_TCP_CLIENT, TCP_ETH_RAM, STACK_MY_HTTPC_TX_SIZE, STACK_MY_HTTPC_RX_SIZE},
      #endif
     
         {TCP_PURPOSE_NGR_TCP_SERVER, TCP_ETH_RAM, 32, 32},
   };
#else
   #undef TCP_CONFIGURATION
   #define TCP_CONFIGURATION 1
   TCPSocketInitializer_t TCPSocketInitializer[TCP_CONFIGURATION] =
   {
      {TCP_PURPOSE_DEFAULT, TCP_ETH_RAM, 250, 250}
   };
#endif


Server opening code:
Code:

socket[i] = TCPOpen(NULL, TCP_OPEN_SERVER, NETWORK.port_tcp_server.d, TCP_PURPOSE_NGR_TCP_SERVER);


Tcp connected task:
Code:
int8 tcp_connected_task(TCP_SOCKET socket, int8 which)
{
    int1 disconnect = FALSE;
    BYTE tcp_reply_str[TCP_BUFFER_SIZE];
    BYTE tcp_str[TCP_BUFFER_SIZE];

    if (TCPIsGetReady(socket))
    {
        // TCP verisi aliniyor -------------------------------------------------
        int16 i=0;
        char c;
        while (TCPGet(socket, &c))
        {
            if( i < TCP_BUFFER_SIZE )
                tcp_str[i++]=c;
        }
       
        debug_write("\r{tcp] RX << ");
        debug_bytes_in_hex(tcp_str, TCP_BUFFER_SIZE);
        debug_writeln(" ");
       
        ngr_parse(tcp_str, tcp_reply_str);
       

        /*debug_write("[tcp] TX >> ");
        debug_bytes_in_hex(tcp_reply_str, TCP_BUFFER_SIZE);
        debug_writeln(" ");*/

        // Cevap gonder --------------------------------------------------------
        TCPPutArray(socket, tcp_reply_str, TCP_BUFFER_SIZE);
        TCPFlush(socket);
    }
    return disconnect;
}


And also I have checked the transmitted data with Hercules if correct.


Board: PIC24FJ256GB106 + ENC28J60
TCP/IP Stack version: 5.42
Compiler version: 5.092
OS: Windows 11
_________________
Compiler v5.091+ Windows 10
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group