Hot!Sending data to microcontroller PIC32

Author
mohammad faizan
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2017/10/24 04:53:06
  • Location: 0
  • Status: offline
2017/12/06 02:52:52 (permalink)
0

Sending data to microcontroller PIC32

Hi,
 I m working on a tcpip tcp client project, harmony 2.04, PIC32 ethernet starter kit II, Mplab 3.65. By which I m sending a text to a server socket (PC). Now as an acknowledgement, I want to blink the LEDs, on and off from a server socket by sending a text start and stop resp. I need to add a receiver buffer in app.c file and  compare a received text   by implement some form of if else statements to examine the contents of the received buffer, and if the correct message "START" was indeed received, execute a function that would start blinking the LEDs, similarly if message "STOP" was  received, execute a function that would stop blinking the LEDs. This code is not allow in harmony, can anyone help me to complete this task, Code for receiver buffer state machine which I can add into my app.c file.
 
int main() 

int x,i; 
TRISD = 0; 
while(1) 

if(x = 'start') 

PORTD = 0xFF; 
for(i=0;i<5000;i++); 

else if(x = 'stop') 

PORTD = 0x00; 
for(i=0;i<5000;i++); 

else 

PORTDbits.RD0 = 1; 
for(i=0;i<5000;i++); 
PORTDbits.RD1 = 1; 
for(i=0;i<5000;i++); 
PORTDbits.RD2 = 1; 
for(i=0;i<5000;i++); 
PORTDbits.RD0 = 0; 
for(i=0;i<5000;i++); 
PORTDbits.RD1 = 0; 
for(i=0;i<5000;i++); 
PORTDbits.RD2 = 0; 
for(i=0;i<5000;i++); 




return (0); 


 Please, can you give me a code for receiver buffer which can receive a text words ('START' & 'STOP'),
Thanking You
 
#1

3 Replies Related Threads

    qɥb
    Monolothic Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Sending data to microcontroller PIC32 2017/12/06 12:10:03 (permalink)
    0
    if(x = 'start') 

    This is not valid C.
    x is an integer variable, it cannot hold a string. You need a "char array" to hold a string.
    ' is used to mark character constants, not strings. Strings start and end with "
    You do comparisons with ==, not = but you cannot do a C comparison directly on a string.
    You must use the standard library call strcmp to do a string comparison, so if x was a char array, then
    if (strcmp(x,"start") == 0)

     
    There are so many errors in your example, I suspect you have never used strings in C before. Please go back to your C textbook and read about them.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #2
    mohammad faizan
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/24 04:53:06
    • Location: 0
    • Status: offline
    Re: Sending data to microcontroller PIC32 2017/12/07 04:22:45 (permalink)
    0
    Thanks,
    Yes I have just started with c programming. I don't know much about coding, specially state machine. 
    I am sending a text from pic32 to server socket(PC), can I used the project for receiving a text from server socket, (send and receive)
    case APP_TCPIP_WAIT_FOR_CONNECTION:
    {
       //char buffer[MAX_URL_SIZE];
      char buffer[150] = "abcdefghijklmnopqrstuvwxyz....";
      if(|TCPIP_TCP_IsConnected(appData.socket))
      {
         break;
       }
      if(TCPIP_TCP_PutIsReady(appData.socket)==0)
       {
         break;
        }
       TCPIP_TCP_ArrayPut(appData.socket,(uint_8t*)buffer,strlen(buffer));
        appData.state = APP_TCPIP_WAIT_FOR_RESPONSE;
    }
    break; 
    It's working, on server socket I received a text, 
    For receiving a text string from  server socket, receiver buffer is required in (tcpip tcp client) app.c, can you help me 
     
     
    IP_MULTI_ADDRESS appRemAddress;
    TCPIP_Helper_StringToIPAddress(appIpv4remHost,&appRemAddress.Ipv4Add);
    Static TCP_PORT appRemPort = 2000;
    char APP_Message_Buffer[MAX_URL_SIZE] = "START";
    char APP_Message_Buffer[MAX_URL_SIZE] = "STOP";
     
    case APP_TCPIP_CONTACT_SERVER:
    Nop();
    appDatasocket = TCPIP_TCP_ClientOpen(IP_ADDRESS_TYPE_IPV4,appRemPort,(IP_MULTI_ADDRESS*)appIPv4RemHost);
    Nop();
    if(appData.socket == INVALID_SOCKET)
    {
    Nop();
    break;
    }
    appData.state = APP_TCPIP_WAIT_FOR_CONNECTION;
    }
    break;
    If client is sending a text to a server, the connection is already established, should we need to add this function  for receiving a text. Can you please help me to add receiver buffer code for tcpip tcp client.
     
     
       
    #3
    mohammad faizan
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2017/10/24 04:53:06
    • Location: 0
    • Status: offline
    Re: Sending data to microcontroller PIC32 2017/12/29 03:54:09 (permalink)
    0
    Hi,
    I have a working code of tcpip tcp client, which is capable of sending a data (text) from PIC32 eth kit to server.
    Here PIC32 as a client and Server socket as a server. I had define a IP and port in app.c,
    case APP_TCPIP_WAITING_FOR_COMMAND:
    {
    IPV4_ADDR addr;
    appData.host = "192.168.1.102";
    TCPIP_Helper_StringToIPAddress(appData.host,&addr);
    appData.socket = TCPIP_TCP_ClientOpen(IP_ADDRESS_TYPE_IPV4,2000,(IP_MULTI_ADDRESS*)&addr);
      .......................
    after that I had define a text message  in
    case APP_TCPIP_WAIT_FOR_CONNECTION:
    {
    char buffer[250] = "Welcome to the world of innovation where we enable the technologies....."
    On server socket I received a message,
    server PC@ 192.1468.1.102  is running on port 2000,
    connection is established
    Welcome to the world of innovation where we enable the technologies
    Here I received the text. 
    PIC32 eth kit is working as a client which is sending a text, I want to use the client for receiving a text from server socket, first, it will send a text and after that it will receive a text from server socket which will turn the leds ON/OFF.
    I need your help, 
    As data is send to server socket, a connection is already established, I want to know that, can I define the port and IP again,
    I had define the following cases for tcpip tcp client// sending
    case APP_TCPIP_WAIT_FOR_IP:
    case APP_TCPIP_WAITING_FOR_COMMAND: (define the ip and port)
    case APP_TCPIP_WAIT_ON_DNS:
    case APP_TCPIP_WAIT_FOR_CONNECTION: (TEXT MESSAGE)
    case APP_TCPIP_WAIT_FOR_RESPONSE:
    I had define the following cases for tcpip tcp client// receiving
    I want to know that can I continue in the same switch(appData.state) or I have to define the another switch,
    case APP_TCPIP_OPENING_CLIENT:
    case APP_TCPIP_WAIT_FOR_CONNECTION:
    case APP_TCPIP_WAIT_FOR_RESPONSE:
    case APP_TCPIP_CLOSING_CONNECTION:
    char App_Message_Buffer[MAX_URL_SIZE] = "START";
    char App_Message_Buffer[MAX_URL_SIZE] = "STOP";
    {
    i = AppBuffer[];
    if(strcmp(i,"START")==0)
    {
    PLIB_PORTS_PinSet( PORTS_ID_0, PORT_CHANNEL_D, led);
    }
    elseif(strcmp(i,"STOP")==0)
    {
     PLIB_PORTS_PinClear( PORTS_ID_0, PORT_CHANNEL_D, led);
    }
    I want to use this function which will compare the received text and make the leds on/off. I need your help, please help me to implement this
     
    #4
    Jump to:
    © 2018 APG vNext Trial Version 4.5