c - Microchip 射频调制器问题

标签 c microchip pic32

我正在使用一对 MRF24J40 radio 芯片来让一个 PIC32 微 Controller 板通过射频传输与另一个微 Controller 板进行通信。我的所有代码都可以正常编译,但我不断收到与此代码相关的错误。

typedef struct
    {
        union
        {
            BYTE        Val;  
            struct
            {
                BYTE    packetType      :2;             // type of packet. Possible types are
                                                        // * PACKET_TYPE_DATA - Data type
                                                        // * PACKET_TYPE_COMMAND -  Command type
                                                        // * PACKET_TYPE_ACK -  Acknowledgement type
                                                        // * PACKET_TYPE_RESERVE - Reserved type
                BYTE    broadcast       :1;             // 1: broadcast, 0: unicast
                BYTE    secEn           :1;             // 1: secure the MAC payload, 0: send plain text
                BYTE    repeat          :1;             // 1: allow repeaters to forward the message, 0: send message directly
                BYTE    ackReq          :1;             // 1: acknowledgement required, 0: no acknowldgement
                BYTE    destPrsnt       :1;             // 1: destination address in the packet, 0: destination address not in the packet
                BYTE    sourcePrsnt     :1;             // 1: source address in the packet, 0: source address not in the packet
            } bits;
        } flags;

        BYTE *      SourceAddress;                      // Address of the Sender
        BYTE *      Payload;                            // Pointer to the payload
        BYTE        PayloadLen;                         // Payload size
        BYTE        RSSIValue;                          // RSSI value for the received packet
        BYTE        LQIValue;                           // LQI value for the received packet
        #if defined(IEEE_802_15_4)
            BOOL        altSourceAddress;               // Source address is the alternative network address
            WORD_VAL    SourcePANID;                    // PAN ID of the sender
        #endif
    } MAC_RECEIVED_PACKET;

基本上,我已经尝试了世界上所有的方法来更改变量 packetTypesecEnackReq 等的值。已尝试在声明后直接更改值,但这似乎是位长度,而不是值。代码(直接来自 microchip 的网站)有注释说 1 = this 和 0 = that,但我还没有找到可以更改这些值的任何地方。如果任何熟悉这些 MRF24J40 芯片的人提供帮助,我们将不胜感激。谢谢。

最佳答案

我认为这与您的微 Controller 没有任何特定关系,只是您可能不熟悉如何使用 structunion 定义位域在 C 中。

MAC_RECEIVED_PACKET 是一个 struct,它有一个名为 flags 的字段。 flagsBYTE 和名为 bitsstruct 位域之间的并集

在声明中,bits 中的每个字段后面都跟着其位长度。因此,例如,2 位的 packetType 可以采用值 0、1、2、3。您可以这样设置值:

MAC_RECEIVED_PACKET foo;
foo.flags.bits.packetType = 3;
foo.flags.bits.secEn      = 1;
/* etc. */

关于c - Microchip 射频调制器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23140087/

相关文章:

将 ASM 转换为 C(不是逆向工程)

c - 如何使timer0使用1 :64 in 16 bit mode?的预分频器

c - 显示先前接收到的 UART 值

c - freeRTOS 中的软件中断

c - ESP32 - 带有本地 LwIP 库的 UDP 广播器/接收器

c - 这个 C 程序如何打印值 1 或 0?

无法使用 TMR4、T4CON 等访问定时器 4 pic32

c - 在数组中预读以预测 C 中的后续结果

c - 如何在C中使用 'fwrite'?

c - 如何防止子进程中的 SIGINT 传播到父进程并杀死父进程?