SOURCES
char i;
ETRX2 from Lemos International
www.lemosint.com
init();
cleaner();
PICC- 18 PRO from HI-TECH Software
www.htsoft.com
//load the receive
//buffer with 0x00
i = 0; //index pointer for
//our_buffer
printf(“AT+N\r\n”); //issue PAN query to
//ETRX2
for(temp16=0;temp16<1000;++temp16);
PIC18LF2620; MPLAB IDE; MPLAB REAL ICE
from Microchip
www.microchip.com
//give ETRX2
//time to
//respond
i= 0;
do{
our_buffer[i++] = recvchar();
receive buffer into your application code. You may now be
wondering how we know when to invoke the recvchar
function. Again, no worries. We periodically call the
CharInQueue function, which tells us if the PIC18LF2620’s
receive buffer is empty or not. As long as the CharInQueue
function informs us that there is a character in the receive
buffer that we want to process, we invoke recvchar. Here’s
an example code snippet that issues the “what PAN are you
playing in” command to the ETRX2 and places its response
in a memory area we call our_buffer:
}while(CharInQueue());
while(1);
//move
//characters
//recv buf ->
//our buf
//get all
//characters in
//the recv
//buffer
//spin here forever
}
//*******************************************************
//* MAIN SERVICE LOOP
//*******************************************************
void main(void)
{
When you look through the memory declarations area
of the ETRX2 driver source code, you’ll see that I created a
32-byte character array called our_buffer in the PIC18LF2620
memory area. I also built and added a function called cleaner.
The cleaner function simply writes zero to every location in
the PIC18LF2620’s receive buffer. The 32-byte character array
our_buffer begins at PIC memory offset 0xF1E in Screenshot
5. Every character in the receive
buffer which begins at offset
0xF3E in Screenshot 5 is duplicated in our_buffer. It’s all a piece
of cake. Just like I promised.
SCREENSHOT 2. I can see the light bulbs going off out there. This is really neat stuff, huh?
The entire functionality of the ETRX2 is now at our disposal.
SCREENSHOT 3. This shows how easy it is to employ the ETRX2’s I/O subsystem as an
extension of the PIC18LF2620’s I/O subsystem. Note that the ETRX2’s inputs are reading
0x00F3 when they are all in the clear.
Out of the Fire and
into the PAN
SCREENSHOT 4. I grounded the zero bit pin of the ETRX2’s input subsystem and ran the same
code we ran for Screenshot 3. The ETRX2’s zero input bit now reads zero just as it should.
SCREENSHOT 5. This shot demonstrates the power of the PIC18LF2620’s EUSART data movement
functions. You now have the power to talk to the ETRX2, gather data and information from the
ETRX2, and use the collected information in your PIC18LF2620 application.
Now that you know how
to issue ETRX2 commands,
retrieve command results, and
use the incoming data in your
application with the
PIC18LF2620, the networking
portion of the ETRX2 equation
is at your disposal. A read
through its command set
document — which can be had
from the Telegesis website
( www.telegesis.com) — will
reveal the ETRX2 AT commands
for forming, joining, and exiting
a ZigBee PAN. You will also find
out how easy it is to read and
write the ETRX2’s I/O lines.
You now have the power to
move data along with the
appendages in your
electromechanical designs. SV
Fred Eady can be reached via
email at fred@edtp.com.
56 SERVO 09.2008