|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
TCP/IP |
Posted: Mon Feb 16, 2004 8:00 pm |
|
|
Can any provide me (or direct me to a web site) a simple implementation of TCP/IP using PIC as the microcontroller.
What I need is a really simple schematic showing a PIC, and other components required and a small workable code (that compiles using CCS) just to show how the TCP/IP is implemented. |
|
|
Izolator
Joined: 10 Feb 2004 Posts: 12 Location: Denmark, (Scandinavia-Europe)
|
|
Posted: Wed Feb 18, 2004 12:18 pm |
|
|
Hi there :-)
I have combined and used the following with great success:
Pic16F877 - Microchip.com
Packet Whacker - edtp.com
EDTP's example:
http://www.edtp.com/download/pw/whacky.exe
Note:
It might take ½hour to figure out what it does/can do, but basicly it is set up for this, amung af few other features:
telnet server / TCP
Echo packet / UDP
Blink led / UDP
Ping / ICMP
I myself didnt have use for the TCP part, only UDP, so I simply removed the telnetserver part, along with all the complex TCP functions.
I think UDP is way easier to figure out.
You will have to decide whether or not to use TCP, UDP or both as per default. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Wed Feb 18, 2004 12:24 pm |
|
|
Try and find a copy of Bentham's book TCP/IP Lean
Or Jan Axelson's book Embedded Ethernet and Internet Complete: Designing and Programming Small Devices for Networking
I think both are available through Amazon.com and if you are lucky maybe a local bookstore _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Feb 19, 2004 8:24 pm |
|
|
Or you could do what I did, and cheat. I used a network module, from www.lantronix.com, called XPORT. It will interface with the PIC via RS232 and take care of communications to the network.
Ronald |
|
|
Kieran
Joined: 28 Nov 2003 Posts: 39 Location: Essex UK
|
Packet Whacker |
Posted: Thu Nov 04, 2004 1:17 pm |
|
|
EDTP Packet Whacker
I have one of these hooked up to a 18F452 and have all the demo programs running.
I want to extend the UDP features and I am stuck.
I am trying to send a string back to a PC with the following
triggered by an incomming UDP message from the PC.
Src and Dest are derived from the incoming message.
Code: |
byte dat_buff[128];
// Src source PORT
// Dest PORT
// *dat string to send
send_UDP(int16 Src, int16 Dest, byte *dat)
{
int16 package_len;
memset(&packet[UDP_data],0,50); // Flush UDP data section of packet
txlen = strlen(dat) + 8; // UDP data + header len
ip_packet_len = 20 + txlen; // Allow for IP header
// Set IP header up
packet[ip_pktlen] = make8(ip_packet_len,1);
packet[ip_pktlen+1] = make8(ip_packet_len,0);
setipaddrs();
// UDP header
packet[UDP_srcport] = make8(Src,1);
packet[UDP_srcport + 1] = Src;
packet[UDP_destport] = make8(Dest,1);
packet[UDP_destport + 1] = Dest;
txlen = strlen(dat) + 8; // UDP data + header len
printf("send %s len %ld\r",dat,txlen);
packet[UDP_len] = make8(txlen,1); // Should be 0 - buffer size
packet[UDP_len + 1] = txlen;
// Write data to packet
strcpy(&packet[UDP_data],dat);
//calculate the UDP checksum
packet[UDP_cksum] = 0x00;
packet[UDP_cksum+1] = 0x00;
hdr_chksum =0;
hdrlen = 0x08;
addr = &packet[ip_srcaddr];
cksum();
hdr_chksum = hdr_chksum + packet[ip_proto];
hdrlen = 0x02;
addr = &packet[UDP_len];
cksum();
hdrlen = make16(packet[UDP_len],packet[UDP_len+1]);
addr = &packet[UDP_srcport];
cksum();
chksum16= ~(hdr_chksum + ((hdr_chksum & 0xFFFF0000) >> 16));
packet[UDP_cksum] = make8(chksum16,1);
packet[UDP_cksum+1] = make8(chksum16,0);
// Calculate length and send
txlen = ip_packet_len + 14; // total packet len
if(txlen < 60)
txlen = 60;
package_len = txlen + 4;
pageheader[enetpacketLenH] = make8(package_len,1); // ????????
pageheader[enetpacketLenL] = package_len;
dump_header();
show_packet();
data_L = make8(txlen,0);
data_H = make8(txlen,1);
// Data to RTL8019
write_creg(CR,0x22);
write_creg(TPSR,txstart);
write_creg(RSAR0,0x00);
write_creg(RSAR1,0x40);
write_creg(ISR,0xFF);
write_creg(RBCR0,data_L);
write_creg(RBCR1,data_H);
write_creg(CR,0x12);
for(i=0;i<(txlen);++i)
write_creg(RDMAPORT,packet[enetpacketDest0+i]);
byte_read = 0;
while(!bit_test(byte_read,RDC))
read_creg(ISR);
write_creg(TBCR0,txlen - 4);
write_creg(TBCR1,make8(txlen,1));
write_creg(RBCR0,data_L);
write_creg(RBCR1,data_H);
write_creg(CR,0x24);
}
|
Calls and variables are from the packet whacker code.
If I replace the code from below the checksum with the Packet Whacker echo_packet() function then all is well. Any ideas?
Kieran |
|
|
|
|
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
|