ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
■ BY PETER BEST
USING ETHERNET INSIDE A PIC
THE MICROCHIP FOLKS OFFER A FREE TCP/IP STACK that works very well
with the PIC18F67J60. That sets Microchip up a notch in my book, as there’s
nothing better than a semiconductor manufacturer that offers a free support
firmware package for its products. However, not every embedded Ethernet
design needs DHCP or TCP capabilities. For instance, if you only need UDP,
in most cases, you’ll still need to load all or the bulk of the stack’s underlying
components which go unused and eat up your microcontroller’s precious Flash
and SRAM resources. About the only way around that situation is to write your
own set of PIC18F67J60 drivers, and that’s just what we’re going to do in this
spin of Design Cycle.
GOING ABOUT IT
The free Microchip TCP/IP stack
supports both the Realtek RTL8019AS
and their own new ENC28J60 stand-alone Ethernet controller, as well as the
PIC18F67J60 and all of its big brothers.
As we progress through the process of
putting together a set of PIC18F67J60
driver routines, I will pull heavily from
Fred Eady’s Realtek RTL8019AS garage
stack that has proven itself over the
years. After all, once you lay down the
basic firmware for performing ARP and
UDP processes, you can apply those
same principles across platforms.
Thus, once the new PIC18F67J60
driver firmware is assembled, there is no
reason that I can think of which will
prevent the Internet protocol code that
works for the RTL8019AS and ENC28J60
to work with the PIC18F67J60. You can
gain a better understanding of Fred’s
RTL8019AS code by getting yourself a
copy of his book on the subject entitled
Networking and Internetworking with
Most of my days are spent doling
out advice to readers about embedded
Ethernet via email messages. When I’m
84 March 2007
not responding to reader emails, I’m
thinking about or designing new stuff.
Recently, I’ve seen reader interest shift
from the RTL8019AS-based technology
to the new Microchip Ethernet engine
technology. The Microchip folks provided an easy out for us with regards to the
ENC28J60 as they provided a full TCP/IP
stack for their new parts up front.
Although that was a good thing
for all of us, rather than try to adapt
the Microchip TCP/IP stack, I’ve
decided to offer some homebrewed
“garage” PIC18F67J60 drivers to fit
our special PIC18F67J60 hardware. If
you need the full power of the
Microchip TCP/IP stack, it will run on
the PIC18F67J60 hardware I presented in the previous portion of this set
of Design Cycle columns.
CODING THE I/O
The PIC18F67J60 Ethernet driver
firmware I’ll provide is constructed
with the HI-TECH PICC18 C compiler.
As you can see in Schematic 1, the
PIC18F67J60 eliminates the need for
an SPI interface between the micro-
controller and the Ethernet engine as
the Ethernet engine is incorporated
into the PIC microcontroller silicon.
Like the ENC28J60, the PIC
18F67J60 is a register-based device. If
you had a chance to take in one of my
ENC28J60 Design Cycle columns, you’ll
note the absence of the ENC28J60
register and memory access commands
in the PIC18F67J60 driver firmware.
Memory access commands are not
needed when using the PIC18F67J60
as the Ethernet control registers are
mapped into the PIC18F67J60’s micro-controller data memory area.
With the PIC18F67J60, we no
longer need to send access
commands to the Ethernet registers
and data buffers via the SPI interface.
Each PIC18F67J60 register has a
unique 12-bit address within the
PIC18F67J60’s data memory area.
The 12-bit register address is
composed of a four-bit Bank Pointer
(0bBBBBxxxxxxxx) and an eight-bit low-order address (0bxxxxAAAAAAAA).
For instance, Bank 15 (0xFxx) contains the analog-to-digital converter
result registers (ADRESH/ADRESL) at
offsets 0xC4 (0bxxxx11000100) and
0xC3 (0bxxxx11000011), respectively.