Пример #1
0
/** Use this to verify that the SPI port is configured correctly and writing bytes
Use a logic analyzer or scope and view the bytes being written.
The ZNP won't do anything but you'll be able to determine whether the SPI port is working.
Configure logic analyzer to trigger on a 1->0 transition on CS.
Verify that you're seeing the bytes written out the SPI port.
 */
int main( void )
{
    halInit();                          //Initialize hardware    
    halSpiInitZnp();
    halInit();
    printf("Test ZNP Reset\r\n");
    RADIO_OFF();
    delayMs(1);
    RADIO_ON();
#define TEST_SRDY_INTERVAL_MS 1  //check SRDY every 100 mSec
#define TEST_SRDY_TIMEOUT_MS  1000
    unsigned int elapsedTime = 0;       //now, poll for SRDY going low...
    do
    {
        delayMs(TEST_SRDY_INTERVAL_MS);
        elapsedTime += TEST_SRDY_INTERVAL_MS;
    }
    while ((elapsedTime < TEST_SRDY_TIMEOUT_MS) && (SRDY_IS_HIGH()));
    if (SRDY_IS_LOW())
    {
        printf("Test PASSED - SRDY went low after approximately %umS\r\n", elapsedTime);
    }
    else
    {
        printf("ERROR - SRDY never went low\r\n");
    }


    printf("SPI Write Test\r\n");
#define TEST_DATA {0x05, 0x04, 0x03, 0x02, 0x01, 0x00}
#define TEST_DATA_LENGTH 6
    unsigned char test[] = TEST_DATA;
    spiWrite(test, TEST_DATA_LENGTH);
    printf("Done!\r\n");
}
Пример #2
0
/** This utility will toggle the reset line of the ZNP and determine whether the ZNP firmware is loaded.
When using SPI, toggling the reset line should cause SRDY to go high after approx. 400mSec to indicate a SYS_RESET_IND message.
This utility doesn't read the SPI bytes, just checks the SRDY line. 
Verify that the pin connected to the hardware reset of the ZNP is pulled down for 1mSec.
Configure logic analyzer to trigger on a 1->0 transition on ZNP reset line*/
int main( void )
{
    halInit();
    printf("Test ZNP Reset\r\n");
    RADIO_OFF();
    delayMs(1);
    RADIO_ON();

#define TEST_SRDY_INTERVAL_MS 1  //check SRDY every 100 mSec
#define TEST_SRDY_TIMEOUT_MS  1000
    unsigned int elapsedTime = 0;       //now, poll for SRDY going low...
    do
    {
        delayMs(TEST_SRDY_INTERVAL_MS);
        elapsedTime += TEST_SRDY_INTERVAL_MS;
    }
    while ((elapsedTime < TEST_SRDY_TIMEOUT_MS) && (SRDY_IS_HIGH()));
    if (SRDY_IS_LOW())
    {
        printf("Test PASSED - SRDY went low after approximately %umS\r\n", elapsedTime);
    }
    else
    {
        printf("ERROR - SRDY never went low\r\n");
    }
}
Пример #3
0
/** Resets the ZNP using hardware and retrieves the SYS_RESET_IND message. 
This method is used to restart the ZNP's internal state machine and apply changes to startup options, zigbee device type, etc.
@post znpResult contains the error code, or ZNP_SUCCESS if success.
@return a pointer to the beginning of the version structure, or a pointer to indeterminate data if error.
@see Interface Specification for order of fields
*/
unsigned char* znpReset()
{
    RADIO_OFF();
    DEBUG_OFF();
    delayMs(1);
    RADIO_ON(); 
    DEBUG_ON();
    znpResult = spiPoll();              //Note: this will be different if UART
    return (znpBuf+SRSP_PAYLOAD_START);  //the beginning of the reset indication string
}
Пример #4
0
/** Reset the ZNP, poll for the SYS_RESET_IND message and display the contents.
 * Similar to the method znpReset() in znp_interface.c */
int main( void )
{
    halInit();                          //Initialize hardware
    halSpiInitZnp();
    printf("Resetting ZNP\r\n");
    RADIO_OFF();
    delayMs(1);
    RADIO_ON();
    spiPoll();
    for (int i=0; i< (znpBuf[0] + 3); i++)
        printf("%02X ", znpBuf[i]);
    printf("\r\n");
}
Пример #5
0
/** Reset the ZNP and then get the MAC. */
int main( void )
{
    halInit();                          //Initialize hardware
    halSpiInitZnp();
    printf("Resetting ZNP to get MAC address\r\n");
    RADIO_OFF();
    delayMs(1);
    RADIO_ON();
    spiPoll();
    for (int i=0; i< (znpBuf[0] + 3); i++)
        printf("%02X ", znpBuf[i]);
    printf("\r\n");
    
    znpBuf[0] = 1;      //ZB_GET_DEVICE_INFO_PAYLOAD_LEN;
    znpBuf[1] = 0x26;   //MSB(ZB_GET_DEVICE_INFO);
    znpBuf[2] = 0x06;   //LSB(ZB_GET_DEVICE_INFO);
    znpBuf[3] = 1;      //DIP_MAC_ADDRESS;
    sendSreq();
    printf("MAC Address, LSB first:");
    for (int i=4; i< (znpBuf[0] + 3); i++)
        printf("%02X ", znpBuf[i]);
    printf("\r\n");
}
Пример #6
0
/** Initializes Ports/Pins: sets direction, interrupts, pullup/pulldown resistors etc. */
void portInit()
{
    //Configure SPI port
    //PRECONDITIONS: GPIO PORTS HAVE BEEN ENABLED & PINS WERE CONFIGURED: PC4, PD5 as outputs; PD6 as input
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);  //FOR Module Control ????
    //SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles

    /* Port A
     * PA0      U0Rx (Only for USB UART - N/A if using RS-232)
     * PA1      U0Tx (Only for USB UART - N/A if using RS-232)
     * PA2      SSI0CLK
     * PA3      SSI0 ChipSelect for OLED screen on LM3S6965 board (NOT USED in our application - leave as input in case R25 mistakenly populated)
     * PA4      SSI0Rx (MISO)
     * PA5      SSI0Tx (MOSI)
     * PA6      USB Sleep input
     * PA7
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* SSI */
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5);
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* Inputs */
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_6);
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_3);
    /* UART */
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    // If interrupts are desired, then enable interrupts on this UART
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    UARTStdioInit(0);  //configures this UART0 as the uart to use for UARTprintf

    /* Port B
     * Pb0      Internal LED1 - "D2" Blue
     * Pb1      Internal LED2 - "D3" Green
     * Pb2		I2C SCL (connected to EEPROM)
     * Pb3		I2C SDA (connected to EEPROM)
     * Pb4      Spare 1 (on header)
     * Pb5      Status LED - Green
     * Pb6      Status LED - Red
     * Pb7      TRSTn - not used
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* Outputs */
    GPIOPadConfigSet(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 | GPIO_PIN_6), GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD);
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 | GPIO_PIN_6));  //configure LEDs

    // I2C:
#ifdef HAL_I2C
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    delayMs(2);
#endif

    /* Port C
     * PC0      JTAG TCK
     * PC1      JTAG TMS
     * PC2      JTAG TDI
     * PC3      JTAG TD0
     * PC4      Module Chip Select
     * PC5      SPI Flash Chip Select
     * PC6      USB RTS (not used)
     * PC7      USB CTS (not used)
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, (GPIO_PIN_4 | GPIO_PIN_5));
    //GPIOPadConfigSet(GPIO_PORTC_BASE, (GPIO_PIN_4 | GPIO_PIN_5), GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);


    /* Port D
     * PD0      Spare 0
     * PD1
     * PD2      Spare Rx
     * PD3      Spare Tx
     * PD4
     * PD5      Module Reset
     * PD6      SRDY
     * PD7
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);  //FOR Module CONTROL
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_5);
    //GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_5, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
    /* Inputs */
    GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6);


    RADIO_OFF();
    SPI_SS_CLEAR();

    /* Port E
     * PE0      Spare
     * PE1      Spare
     * PE2      Spare
     * PE3      Internal button
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* Inputs */
    GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_3 , GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD);
    GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_3, GPIO_DIR_MODE_IN);
    GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_3, GPIO_RISING_EDGE); // Make button a falling-edge triggered interrupt
    GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_3);                  // Enable the interrupt on this pin
    GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_3);                   //Clear interrupts
    IntEnable(INT_GPIOE);                                           //enable interrupt 18

    /* Port F
     * PF0      Internal LED0 - "D1" Red
     * PF1      External button
     * PF2		Ethernet LED1 (Rx or Tx Activity)
     * PF3		Ethernet LED0 (Link Ok)
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);  //configure LED
    /* Inputs */
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1 , GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD);
    GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN);
    GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_RISING_EDGE); // Make button a falling-edge triggered interrupt
    GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1);                  // Enable the interrupt on this pin
    GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1);                   //Clear interrupts
    IntEnable(INT_GPIOF);                                           //enable interrupt 18
    /* Ethernet LEDs */
    GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_HW);
    GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_2|GPIO_PIN_3,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);

    return;

    /* Port G
     * PG0      UART2 Rx
     * PG1      UART2 Tx
     */
#ifdef USE_UART2
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    SysCtlDelay(10); //delay by (3 * 10) 30 clock cycles

    GPIOPinTypeUART(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    // Configure the UART for 115,200, 8-N-1 operation.
    //UARTConfigSetExpClk(UART2_BASE, SysCtlClockGet(), 115200,
    //		(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    // Enable the UART interrupt.
    IntEnable(INT_UART2);

    UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);
    //UARTStdioInit(2);  //configures this UART0 as the uart to use for UARTprintf
#else
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    /* already done in port A
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    // If interrupts are desired, then enable interrupts on this UART
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
    UARTStdioInit(0);  //configures this UART0 as the uart to use for UARTprintf
    */
#endif

}
Пример #7
0
/** Initializes Ports/Pins: sets direction, interrupts, pullup/pulldown resistors etc. */
void portInit()
{
    /* Port A
     * PA0      U0Rx (Debug UART)
     * PA1      U0Tx (Debug UART)
     * PA2      Bit-Bang I2C SDA
     * PA3      Bit-Bang I2C SCL
     * PA4      BoosterPack RGB LED - Green
     * PA5      Module SS & MRDY
     * PA6		BoosterPack RGB LED - Red
     * PA7		Module SRDY
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    PERIPHERAL_ENABLE_DELAY();
    /* Configure UART pins */
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
    GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_6, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD); // For LEDs
    /* Inputs */
    GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_7);
    /* Bit-bang I2C */
    //GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_DIR_MODE_OUT);  //SDA & SCL
    //GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_OD);  //SDA & SCL open-drain
    //GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_PIN_2 | GPIO_PIN_3);  //Set SDA & SCL high


    /* Port B
     * PB0
     * PB1
     * PB2		BoosterPack RGB LED - Blue
     * PB3
     * PB4		Module SCLK		SSI2CLK
     * PB5      LED0
     * PB6      Module MISO		SSI2Rx
     * PB7		Module MOSI		SSI2Tx
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);  //FOR STATUS LED
    PERIPHERAL_ENABLE_DELAY();
    /* SSI2 Configuration for Module SPI */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
    PERIPHERAL_ENABLE_DELAY();
    GPIOPinConfigure(GPIO_PB4_SSI2CLK);
    GPIOPinConfigure(GPIO_PB6_SSI2RX);
    GPIOPinConfigure(GPIO_PB7_SSI2TX);
    GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_5);
    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_5, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);

    /* Port C
     * PC0		(JTAG TCK/SWCLK)
     * PC1		(JTAG TMS/SWDIO)
     * PC2		(JTAG TDI)
     * PC3		(JTAG TDIO/SWO)
     * PC4
     * PC5
     * PC6
     * PC7
     */
    // Note: no initialization needed for Port C required; using default configuration

    /* Port D
     * PD0		I2C3SCL
     * PD1		I2C3SDA
     * PD2
     * PD3
     * PD4		(USB D-)
     * PD5      (USB D+)
     * PD6
     * PD7		(USB VBUS)
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);  //FOR STATUS LED
    PERIPHERAL_ENABLE_DELAY();
    /* I2C Configuration */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); //requires 5 clock cycles to initialize
    PERIPHERAL_ENABLE_DELAY();
    GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0); //NOTE: Only required for blizzard (LM4F) parts
    GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
    GPIOPinConfigure(GPIO_PD0_I2C3SCL);
    GPIOPinConfigure(GPIO_PD1_I2C3SDA);
#ifdef TIVA
    I2CMasterInitExpClk(I2C3_BASE, SysCtlClockGet(), false); //FALSE = 100kbps
#else
    I2CMasterInitExpClk(I2C3_MASTER_BASE, SysCtlClockGet(), false); //FALSE = 100kbps
#endif

    SysCtlDelay(10000); //otherwise portion of SlaveAddrSet() lost - only for blizzard

    /* Port E - note this port is only 6 pins
     * PE0		Module Reset
     * PE1
     * PE2
     * PE3
     * PE4		Switch S2 on BoosterPack - note has external 47k pullup on BoosterPack
     * PE5      Current Sensor analog input
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    PERIPHERAL_ENABLE_DELAY();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    PERIPHERAL_ENABLE_DELAY();
    /* Outputs */
    GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0);
    /* Inputs */
    GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_4 , GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD);
    GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE); // Make button a falling-edge triggered interrupt
#ifdef TIVA
    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_4);					// Enable the interrupt on this pin
    GPIOIntClear(GPIO_PORTE_BASE, GPIO_PIN_4);					//Clear interrupts
#else
    GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_4);					// Enable the interrupt on this pin
    GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_4);					//Clear interrupts
#endif
    IntEnable(INT_GPIOE);//enable interrupt 18

    /* ADC Inputs */
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);

    RADIO_OFF();
    SPI_SS_CLEAR();

    /* Port F
     * PF0      Switch SW2 on Stellaris LaunchPad
     * PF1		RGB LED on Stellaris LaunchPad - Red
     * PF2		RGB LED on Stellaris LaunchPad - Green
     * PF3		RGB LED on Stellaris LaunchPad - Blue
     * PF4		Switch SW1 on Stellaris LaunchPad
     */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    PERIPHERAL_ENABLE_DELAY();
    /* Outputs */
    // Note: PWM Outputs for LEDs are initialized separately if they are being used
    /* Inputs */
    // Unlock PF0 so we can change it to a GPIO input. see ButtonsInit() in buttons.c in example qs-rgb
    // Once we have enabled (unlocked) the commit register then re-lock it
    // to prevent further changes.  PF0 is muxed with NMI thus a special case.
#ifdef TIVA
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
#else
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
#endif
    HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
    HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
    GPIODirModeSet(GPIO_PORTF_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN);
    GPIOPadConfigSet(GPIO_PORTF_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(GPIO_PORTF_BASE, ALL_BUTTONS, GPIO_FALLING_EDGE); // Make button a falling-edge triggered interrupt
#ifdef TIVA
    GPIOIntEnable(GPIO_PORTF_BASE, ALL_BUTTONS);                  // Enable the interrupt on this pin
    GPIOIntClear(GPIO_PORTF_BASE, ALL_BUTTONS);                   //Clear interrupts
#else
    GPIOPinIntEnable(GPIO_PORTF_BASE, ALL_BUTTONS);                  // Enable the interrupt on this pin
    GPIOPinIntClear(GPIO_PORTF_BASE, ALL_BUTTONS);                   //Clear interrupts
#endif

    IntEnable(INT_GPIOF);
}