微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > 射频无线通信设计 > 求助:zigbee两个测温节点总有一个为0

求助:zigbee两个测温节点总有一个为0

时间:10-02 整理:3721RD 点击:
我设计的无限温度传感网络由一个路由设备和两个温度测量节点组成。两个测温节点的程序应该是一样的吧?我是通过长地址IEEE地址)来在路由设备上区分两个节点的数据的,部分原代码如下:
unsigned int current_temperature1 = 0;
unsigned int current_temperature2 = 0;
unsigned char get_long_addr[8];
unsigned char get_dat[2];
unsigned char Is_node1 = 0;
float f_temper = 0;
static void LocDongle_ProcessMSGCmd( afIncomingMSGPacket_t *pkt )
{
UART_SendMsg.start_frame = 0xff;
UART_SendMsg.cmd = (uint8)(pkt->clusterId);
get_dat[0] = *(pkt->cmd.Data++);
get_dat[1] = *(pkt->cmd.Data++);

// osal_memcpy (UART_SendMsg.dat, pkt->cmd.Data, 10);
osal_memcpy (get_long_addr, pkt->cmd.Data, 8);

if(get_long_addr[0] == 0xff && get_long_addr[1] == 0xff && get_long_addr[2] == 0xff
&& get_long_addr[3] == 0xff && get_long_addr[4] == 0xff && get_long_addr[5] == 0xff
&& get_long_addr[6] == 0xff && get_long_addr[7] == 0x00)
Is_node1 = 1;
else
Is_node1 = 0;



if(UART_SendMsg.cmd == TAS_READ_TEMPERATURE)
{
if(Is_node1)
{
current_temperature1 = get_dat[1];
current_temperature1 = current_temperature1 << 8;
current_temperature1 += get_dat[0];
if(current_temperature1 > 0x0800)//负数
{
current_temperature1 = 0xfff - current_temperature1 +1;
Print8(HAL_LCD_LINE_2,50,"-",1);
}
else
Print8(HAL_LCD_LINE_2,50,"+",1);
f_temper =current_temperature1 * 0.0625;
current_temperature1 = f_temper;
Printn8(HAL_LCD_LINE_2,60,current_temperature1,1,4);
Print16(HAL_LCD_LINE_2,95,"℃",1);
}
else
{
current_temperature2 = UART_SendMsg.dat[1];

current_temperature2 = current_temperature2 << 8;
current_temperature2 += UART_SendMsg.dat[0];
if(current_temperature2 > 0x0800)//负数
{
current_temperature2 = 0xfff - current_temperature2 +1;
Print8(HAL_LCD_LINE_2,50,"-",1);
}
else
Print8(HAL_LCD_LINE_3,50,"+",1);
f_temper =current_temperature2 * 0.0625;
current_temperature2 = f_temper;
Printn8(HAL_LCD_LINE_3,60,current_temperature2,1,4);
Print16(HAL_LCD_LINE_3,95,"℃",1);
}

}
}

程序中 if(get_long_addr[0] == 0xff && get_long_addr[1] == 0xff && get_long_addr[2] == 0xff
&& get_long_addr[3] == 0xff && get_long_addr[4] == 0xff && get_long_addr[5] == 0xff
&& get_long_addr[6] == 0xff && get_long_addr[7] == 0x00 )
是判断数据包来自哪个节点,判断条件中的地址是第一个节点的IEEE地址,另一个差不多,只是get_long_addr[7] == 0x01,。两个节点的程序是一样的。但是运行时,就只有get_long_addr[7] == 0x00,也就是第一个节点的温度能正常显示在路由设备的液晶屏上,为“+0027℃”(也能随环境温度而变化),另一个则总是显示“+0000℃”。而如果我把上面那个判断地址的if语句的条件改成
if(get_long_addr[0] == 0xff && get_long_addr[1] == 0xff && get_long_addr[2] == 0xff
&& get_long_addr[3] == 0xff && get_long_addr[4] == 0xff && get_long_addr[5] == 0xff
&& get_long_addr[6] == 0xff && get_long_addr[7] == 0x01 )
就变成第二个节点的温度正常显示,第一个节点总是显示“+0000℃”了!
请大家帮帮忙,看看问题在哪儿。要要是觉得我描述的不够清楚,麻烦回帖指出。谢谢!

我是新手,不懂,是来学习的。

楼主你好,我想请问一下,你做的温度传感是否是用的芯片自带的温度传感器.

CC2530么?

看了下程序,感觉你的current_temperature1和current_temperature2在同一个if里面的话,就可以只用current_temperature就可以了的,像你如果这样写的话,下面发送的时候还要写两遍关于current_temperature2发送的。我觉得问题有可能出在你的那个判断地址上面,else之后是第二个节点,这边的else改成和上面的if一样的判断,只把最后一个地址改一下的。

嘻嘻,这不知道行不行的,楼主可以试下的。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top