ZHDA134 April 2026 CC1310 , CC1311P3 , CC1312PSIP , CC1312R , CC1312R7 , CC1314R10 , CC1350 , CC1352P , CC1352P7 , CC1352R , CC1354P10 , CC1354R10
在某些情况下,即便采用标准数据包格式,用户仍希望使用高级命令发送数据包。这可能是因为用户需要发送标准 TX 命令所不支持的更长前导码,侦听模式应用就是典型场景。
SysConfig (3) 和 SmartRF Studio (2) 均支持导入和导出 PHY 默认配置以外的其他命令。图 2-2 展示了如何使用 SysConfig 选择要导入到项目中的额外命令,而且图 2-3 展示了如何使用 SmartRF Studio 进行代码导出以完成此操作。
图 2-2 在 SysConfig 中同时导入标准命令与高级 TX 命令
图 2-3 在 SmartRF Studio 中同时导出标准命令与高级 TX 命令通过这种方式添加额外命令时,SmartRF Studio 与 SysConfig 生成的配置并不完全相同,因此示例代码的编写兼容了两种工具的输出结果。使用高级 TX 命令时,长度字节必须与有效载荷一起手动写入数据包,并且命令的 .pktLen 字段必须同时包含长度字段和有效载荷长度。代码示例如下所示。
1: //---------------------------------------------------------------------------------------------
2: // Transmit Standard Packet Format with CMD_PROP_TX_ADV (1 Length Byte)
3: //---------------------------------------------------------------------------------------------
4:
5: // Defines
6: #define PAYLOAD_LENGTH 3 // Max 255 bytes
7: #define LENGTH_FIELD 1
8:
9: uint8_t packet[LENGTH_FIELD + PAYLOAD_LENGTH];
10:
11: static RF_Object rfObject;
12: static RF_Handle rfHandle;
13:
14: void *mainThread(void *arg0)
15: {
16: RF_Params rfParams;
17: RF_Params_init(&rfParams);
18:
19: RF_cmdPropTxAdv.numHdrBits = 0x0; // Settings that must change to support
20: // the standard packet format
21:
22: RF_cmdPropTxAdv.pktLen = LENGTH_FIELD + PAYLOAD_LENGTH; // Application specific settings
23: RF_cmdPropTxAdv.pPkt = packet;
24:
25: // Settings to modify if going from a PHY that uses the standard TX command
26: // to use the advanced TX command
27: RF_cmdPropTxAdv.condition.rule = 0x1;
28: RF_cmdPropTxAdv.pktConf.bUseCrc = 0x1;
29:
30: rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup,
31: &rfParams);
31: RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
32:
33: while(1)
34: {
35: //-------------------------------------------------------------------------------------
36: // Could be placed outside the while(1) since the packet does not change
37: packet[0] = PAYLOAD_LENGTH;
38:
39: for (uint16_t i = 1; i < (LENGTH_FIELD + PAYLOAD_LENGTH); i++)
40: {
41: packet[i] = i;
42: }
43: //-------------------------------------------------------------------------------------
44: RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTxAdv, RF_PriorityNormal, NULL, 0);
45: RF_yield(rfHandle);
46: usleep(500000);
47: }
48: }