无线点灯求助
时间:10-02
整理:3721RD
点击:
小弟初学ZIGBEE 在做无线点灯实验中遇到了麻烦,在TI上下在的程序代码,修改后烧到板子里,但是两块板子根本没有交互啊
代码如下
发送:
#include <hal_lcd.h>
#include <hal_led.h>
#include <hal_joystick.h>
#include <hal_assert.h>
#include <hal_board.h>
#include <hal_int.h>
#include "hal_mcu.h"
#include "hal_button.h"
#include "hal_rf.h"
#include "util_lcd.h"
#include "basic_rf.h"
/***********************************************************************************
* CONSTANTS
*/
// Application parameters
#define RF_CHANNEL 25 // 2.4 GHz RF channel
// BasicRF address definitions
#define PAN_ID 0x2007
#define SWITCH_ADDR 0x2520
#define LIGHT_ADDR 0xBEEF
#define APP_PAYLOAD_LENGTH 1
#define LIGHT_TOGGLE_CMD 0
// Application states
#define IDLE 0
#define SEND_CMD 1
// Application role
#define NONE 0
#define SWITCH 1
#define LIGHT 2
#define APP_MODES 2
/***********************************************************************************
* LOCAL VARIABLES
*/
static uint8 pTxData[APP_PAYLOAD_LENGTH];
static basicRfCfg_t basicRfConfig;
#ifdef SECURITY_CCM
// Security key
static uint8 key[]= {
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
};
#endif
/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appSwitch();
/***********************************************************************************
* @fn appSwitch
*
* @brief Application code for switch application. Puts MCU in
* endless loop to wait for commands from from switch
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pTxData - file scope variable. Pointer to buffer for TX
* payload
* appState - file scope variable. Holds application state
*
* @return none
*/
static void appSwitch()
{
halLcdWriteLine(HAL_LCD_LINE_1, "Switch");
halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push");
halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
#endif
pTxData[0] = LIGHT_TOGGLE_CMD;
// Initialize BasicRF
basicRfConfig.myAddr = SWITCH_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED)
{
HAL_ASSERT(FALSE);
}
// Keep Receiver off when not needed to save power
basicRfReceiveOff();
// Main loop
while (TRUE)
{
if( halJoystickPushed() )
{
basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH);//发送数据
// Put MCU to sleep. It will wake up on joystick interrupt
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
}
}
/***********************************************************************************
* @fn main
*
* @brief This is the main entry of the "Light Switch" application.
* After the application modes are chosen the switch can
* send toggle commands to a light device.
*
* @param basicRfConfig - file scope variable. Basic RF configuration
* data
* appState - file scope variable. Holds application state
*
* @return none
*/
void main(void)
{
uint8 appMode=NONE;
// Config basicRF
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
basicRfConfig.securityKey = key;
#endif
// Initalise board peripherals
halBoardInit();
halJoystickInit();
// Initalise hal_rf
if(halRfInit()==FAILED)
{
HAL_ASSERT(FALSE);
}
// Indicate that device is powered
halLedSet(2);
halLedClear(1);
// Wait for user to press S1 to enter menu
while (halButtonPushed()!=HAL_BUTTON_1);
halMcuWaitMs(350);
halLcdClear();
appSwitch();//按键发送数据
// Role is undefined. This code should not be reached
HAL_ASSERT(FALSE);
}
接收:
#include <hal_lcd.h>
#include <hal_led.h>
#include <hal_joystick.h>
#include <hal_assert.h>
#include <hal_board.h>
#include <hal_int.h>
#include "hal_mcu.h"
#include "hal_button.h"
#include "hal_rf.h"
#include "util_lcd.h"
#include "basic_rf.h"
/***********************************************************************************
* CONSTANTS
*/
// Application parameters
#define RF_CHANNEL 25 // 2.4 GHz RF channel
// BasicRF address definitions
#define PAN_ID 0x2007
#define SWITCH_ADDR 0x2520
#define LIGHT_ADDR 0xBEEF
#define APP_PAYLOAD_LENGTH 1
#define LIGHT_TOGGLE_CMD 0
// Application states
#define IDLE 0
#define SEND_CMD 1
// Application role
#define NONE 0
#define SWITCH 1
#define LIGHT 2
#define APP_MODES 2
/***********************************************************************************
* LOCAL VARIABLES
*/
static uint8 pRxData[APP_PAYLOAD_LENGTH];
static basicRfCfg_t basicRfConfig;
#ifdef SECURITY_CCM
// Security key
static uint8 key[]= {
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
};
#endif
/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appLight();
/***********************************************************************************
* @fn appLight
*
* @brief Application code for light application. Puts MCU in endless
* loop waiting for user input from joystick.
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pRxData - file scope variable. Pointer to buffer for RX data
*
* @return none
*/
static void appLight()
{
halLcdWriteLine(HAL_LCD_LINE_1, "Light");
halLcdWriteLine(HAL_LCD_LINE_2, "Ready");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_RX, 1);
#endif
// Initialize BasicRF
basicRfConfig.myAddr = LIGHT_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED) {
HAL_ASSERT(FALSE);
}
basicRfReceiveOn();
// 循环接收数据并显示
while (TRUE)
{
while(!basicRfPacketIsReady());
if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0)
{
if(pRxData[0] == LIGHT_TOGGLE_CMD)
{
halLedToggle(1);//点亮LED1
}
}
}
}
/***********************************************************************************
* @fn main
*
* @brief This is the main entry of the "Light Switch" application.
* After the application modes are chosen the switch can
* send toggle commands to a light device.
*
* @param basicRfConfig - file scope variable. Basic RF configuration
* data
* appState - file scope variable. Holds application state
*
* @return none
*/
void main(void)
{
// 初始化无线设备
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
basicRfConfig.securityKey = key;
#endif
// Initalise board peripherals
halBoardInit();
halJoystickInit();
// Initalise hal_rf
if(halRfInit()==FAILED) {
HAL_ASSERT(FALSE);
}
// Indicate that device is powered
halLedSet(2);
// 按S1键申请绑定
while (halButtonPushed()!=HAL_BUTTON_1);
halMcuWaitMs(350);
halLcdClear();
appLight();//数据接收
// Role is undefined. This code should not be reached
HAL_ASSERT(FALSE);
请大神们帮我看看 具体问题在哪儿 跪谢
代码如下
发送:
#include <hal_lcd.h>
#include <hal_led.h>
#include <hal_joystick.h>
#include <hal_assert.h>
#include <hal_board.h>
#include <hal_int.h>
#include "hal_mcu.h"
#include "hal_button.h"
#include "hal_rf.h"
#include "util_lcd.h"
#include "basic_rf.h"
/***********************************************************************************
* CONSTANTS
*/
// Application parameters
#define RF_CHANNEL 25 // 2.4 GHz RF channel
// BasicRF address definitions
#define PAN_ID 0x2007
#define SWITCH_ADDR 0x2520
#define LIGHT_ADDR 0xBEEF
#define APP_PAYLOAD_LENGTH 1
#define LIGHT_TOGGLE_CMD 0
// Application states
#define IDLE 0
#define SEND_CMD 1
// Application role
#define NONE 0
#define SWITCH 1
#define LIGHT 2
#define APP_MODES 2
/***********************************************************************************
* LOCAL VARIABLES
*/
static uint8 pTxData[APP_PAYLOAD_LENGTH];
static basicRfCfg_t basicRfConfig;
#ifdef SECURITY_CCM
// Security key
static uint8 key[]= {
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
};
#endif
/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appSwitch();
/***********************************************************************************
* @fn appSwitch
*
* @brief Application code for switch application. Puts MCU in
* endless loop to wait for commands from from switch
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pTxData - file scope variable. Pointer to buffer for TX
* payload
* appState - file scope variable. Holds application state
*
* @return none
*/
static void appSwitch()
{
halLcdWriteLine(HAL_LCD_LINE_1, "Switch");
halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push");
halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
#endif
pTxData[0] = LIGHT_TOGGLE_CMD;
// Initialize BasicRF
basicRfConfig.myAddr = SWITCH_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED)
{
HAL_ASSERT(FALSE);
}
// Keep Receiver off when not needed to save power
basicRfReceiveOff();
// Main loop
while (TRUE)
{
if( halJoystickPushed() )
{
basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH);//发送数据
// Put MCU to sleep. It will wake up on joystick interrupt
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
}
}
/***********************************************************************************
* @fn main
*
* @brief This is the main entry of the "Light Switch" application.
* After the application modes are chosen the switch can
* send toggle commands to a light device.
*
* @param basicRfConfig - file scope variable. Basic RF configuration
* data
* appState - file scope variable. Holds application state
*
* @return none
*/
void main(void)
{
uint8 appMode=NONE;
// Config basicRF
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
basicRfConfig.securityKey = key;
#endif
// Initalise board peripherals
halBoardInit();
halJoystickInit();
// Initalise hal_rf
if(halRfInit()==FAILED)
{
HAL_ASSERT(FALSE);
}
// Indicate that device is powered
halLedSet(2);
halLedClear(1);
// Wait for user to press S1 to enter menu
while (halButtonPushed()!=HAL_BUTTON_1);
halMcuWaitMs(350);
halLcdClear();
appSwitch();//按键发送数据
// Role is undefined. This code should not be reached
HAL_ASSERT(FALSE);
}
接收:
#include <hal_lcd.h>
#include <hal_led.h>
#include <hal_joystick.h>
#include <hal_assert.h>
#include <hal_board.h>
#include <hal_int.h>
#include "hal_mcu.h"
#include "hal_button.h"
#include "hal_rf.h"
#include "util_lcd.h"
#include "basic_rf.h"
/***********************************************************************************
* CONSTANTS
*/
// Application parameters
#define RF_CHANNEL 25 // 2.4 GHz RF channel
// BasicRF address definitions
#define PAN_ID 0x2007
#define SWITCH_ADDR 0x2520
#define LIGHT_ADDR 0xBEEF
#define APP_PAYLOAD_LENGTH 1
#define LIGHT_TOGGLE_CMD 0
// Application states
#define IDLE 0
#define SEND_CMD 1
// Application role
#define NONE 0
#define SWITCH 1
#define LIGHT 2
#define APP_MODES 2
/***********************************************************************************
* LOCAL VARIABLES
*/
static uint8 pRxData[APP_PAYLOAD_LENGTH];
static basicRfCfg_t basicRfConfig;
#ifdef SECURITY_CCM
// Security key
static uint8 key[]= {
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
};
#endif
/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appLight();
/***********************************************************************************
* @fn appLight
*
* @brief Application code for light application. Puts MCU in endless
* loop waiting for user input from joystick.
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pRxData - file scope variable. Pointer to buffer for RX data
*
* @return none
*/
static void appLight()
{
halLcdWriteLine(HAL_LCD_LINE_1, "Light");
halLcdWriteLine(HAL_LCD_LINE_2, "Ready");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_RX, 1);
#endif
// Initialize BasicRF
basicRfConfig.myAddr = LIGHT_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED) {
HAL_ASSERT(FALSE);
}
basicRfReceiveOn();
// 循环接收数据并显示
while (TRUE)
{
while(!basicRfPacketIsReady());
if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0)
{
if(pRxData[0] == LIGHT_TOGGLE_CMD)
{
halLedToggle(1);//点亮LED1
}
}
}
}
/***********************************************************************************
* @fn main
*
* @brief This is the main entry of the "Light Switch" application.
* After the application modes are chosen the switch can
* send toggle commands to a light device.
*
* @param basicRfConfig - file scope variable. Basic RF configuration
* data
* appState - file scope variable. Holds application state
*
* @return none
*/
void main(void)
{
// 初始化无线设备
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
basicRfConfig.securityKey = key;
#endif
// Initalise board peripherals
halBoardInit();
halJoystickInit();
// Initalise hal_rf
if(halRfInit()==FAILED) {
HAL_ASSERT(FALSE);
}
// Indicate that device is powered
halLedSet(2);
// 按S1键申请绑定
while (halButtonPushed()!=HAL_BUTTON_1);
halMcuWaitMs(350);
halLcdClear();
appLight();//数据接收
// Role is undefined. This code should not be reached
HAL_ASSERT(FALSE);
请大神们帮我看看 具体问题在哪儿 跪谢
没看清楚还以为楼主的弟弟初中就学这 表示好多英语 没看懂
是用电磁感应做的,什么主控啊?
用的CC2530
没有具体的问题,贴这么长的代码没有会看的
