Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC on a PIC using Sockets

Status
Not open for further replies.

Alan_Bates

New Member
Hello all. I'm using a PIC with built in ethernet and berkley sockets. I'm reading in a value from the ADC which I want to send every time the PIC receives a message. I have the following code:

Code:
case BSD_OPERATION:
    if(recv(bsdClientSocket, recvBuffer, 0, 2) < 0) //get the connection status
    {
                BSDClientState = BSD_SEND;
		ConvertADC(); // Start conversion
    }
            break;

 case BSD_SEND:
                 
			if(BusyADC())
			{
				break;
			}
			else
			{
				tempValue = ReadADC();

				sprintf(buf, "%d\n", tempValue);

	            send(bsdClientSocket, (const char*)buf, strlen((char*)buf), 0);  

	            BSDClientState = BSD_OPERATION;
			}

			
            break;

My program on the other end sends a message with send() and then goes to recv(). This does not work, I received nothing. If I take out the recv() part and get the other program to just recv() messages from ym PIC I get about a dozen ADC values before it stops for some reason.

Does anyone have any idea?

What I want to do, is have the server send my PIC a message with "00" and the PIC checks the recv() and replys with the value from the ADC, then goes back to recv() to wait for another message.

Any help would be much appreciated!

EDIT: I've managed to get recv() to work a bit... I send on my java application and get a reply, but after a few seconds it cuts out. If I decrease the sleep() in my java application from 1000 to 500 I get 4 replys, if I decreasing it to 250 I get 8. If I don't wait at all I get a few dozen replys before it cuts out. I'm pretty sure I'm not over flowing any buffers, just after 2 seconds it stops. I tried sending hard coded values instead of using the ADC to see if that made any difference, but it did not.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top