|
Advance Member
|
// *********************************************************************
// Place any non-ZigBee related processing here. Be sure that the code
// will loop back and execute ZigBeeTasks() in a timely manner.
// *********************************************************************
}
}
/*******************************************************************************
HardwareInit
All port directioning and SPI must be initialized before calling ZigBeeInit().
For demonstration purposes, required signals are configured individually.
*******************************************************************************/
void HardwareInit(void)
{
//-------------------------------------------------------------------------
// This section is required to initialize the PICDEM Z for the CC2420
// and the ZigBee Stack.
//-------------------------------------------------------------------------
SPIInit();
// CC2420 I/O assignments with respect to PIC:
//NOTE: User must make sure that pin is capable of correct digital operation.
// This may require modificaiton of which pins are digital and analog.
//NOTE: The stack requires that the SPI interface be located on LATC3 (SCK),
// RC4 (SO), and LATC5 (SI).
//NOTE: The appropriate config bit must be set such that FIFOP is the CCP2
// input pin. The stack uses the CCP2 interrupt.
// Start with CC2420 disabled and not selected
PHY_CSn = 1;
PHY_VREG_EN = 0;
PHY_RESETn = 1;
// Set the directioning for the CC2420 pin connections.
PHY_FIFO_TRIS = 1; // FIFO (Input)
PHY_SFD_TRIS = 1; // SFD (Input - Generates interrupt on falling edge)
PHY_FIFOP_TRIS = 1; // FIFOP (Input - Used to detect overflow, CCP2 interrupt)
PHY_CSn_TRIS = 0; // CSn (Output - to select CC2420 SPI slave)
PHY_VREG_EN_TRIS = 0; // VREG_EN (Output - to enable CC2420 voltage regulator)
PHY_RESETn_TRIS = 0; // RESETn (Output - to reset CC2420)
// Initialize the SPI pins and directions
LATC3 = 1; // SCK
LATC5 = 1; // SDO
TRISC3 = 0; // SCK
TRISC4 = 1; // SDI
TRISC5 = 0; // SDO
// Initialize the SPI module
SSPSTAT = 0xC0;
SSPCON1 = 0x20;
//-------------------------------------------------------------------------
// This section is required for application-specific hardware
// initialization.
//-------------------------------------------------------------------------
// D1 and D2 are on RA0 and RA1 respectively, and CS of the TC77 is on RA2.
// Make PORTA digital I/O.
ADCON1 = 0x0F;
// Deselect the TC77 temperature sensor (RA2)
LATA = 0x04;
// Make RA0, RA1, RA2 and RA4 outputs.
TRISA = 0xE0;
// Clear the RBIF flag (INTCONbits.RBIF)
RBIF = 0;
// Enable PORTB pull-ups (INTCON2bits.RBPU)
RBPU = 0;
// Make the PORTB switch connections inputs.
TRISB4 = 1;
TRISB5 = 1;
}
/*******************************************************************************
User Interrupt Handler
The stack uses some interrupts for its internal processing. Once it is done
checking for its interrupts, the stack calls this function to allow for any
additional interrupt processing.
*******************************************************************************/
void UserInterruptHandler(void)
{
// *************************************************************************
// Place any application-specific interrupt processing here
// *************************************************************************
}
|