2014-04-17 3 views
0

MRF24J40 라디오 칩을 사용하여 하나의 PIC32 마이크로 컨트롤러 보드가 RF 전송을 통해 다른 하나와 통신하게합니다. 모든 코드가 제대로 컴파일되었지만이 코드와 관련된 오류가 계속 발생합니다. 지구에마이크로 칩 RF 변조기 문제

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; 

기본적으로 내가 해봤 다 내가 직접 선언 후 값을 변경하려고했습니다 ackReq 등 변수 packetType, secEn의 값을 변경 할 수 있지만 그 비트 것 같다 길이가 아닌 값. 마이크로 칩의 웹 사이트에서 나온 코드에는 1 = this와 0 =이 있지만 그 값을 변경할 수있는 곳을 찾을 수 없다는 주석이 있습니다. 이 MRF24J40 칩에 익숙한 사람의 도움을 받아 주시면 감사하겠습니다. 고맙습니다.

답변

0

나는이 당신의 마이크로 컨트롤러와 함께 할 수있는 특정 아무것도 있다고 생각하지 않는다, 당신이 C.

MAC_RECEIVED_PACKET에 비트 필드를 정의하는 데 사용되는 방법 structunion에 익숙하지 않을 수 있다는 것을 단지가있는 struct입니다 flags이라는 필드 flagsBYTEstruct 비트 필드 사이에 bits이라는 union입니다.

선언에서 각 필드는 bits 다음에 비트 길이가옵니다. 따라서, 예를 들면, 2 비트 값 0, 1, 2에 걸릴 수있다 packetType는 3. 당신은 다음과 같이 값을 설정 :

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

당신이 당신이 시도한 것을 말할 때 무엇을 의미하는지에 따라 달라집니다

00 =0 --> PACKET_TYPE_DATA 
01 =1 --> PACKET_TYPE_COMMAND 
10 =2 --> PACKET_TYPE_ACK 
11 =3 --> PACKET_TYPE_RESERVE 

이유 :

MAC_RECEIVED_PACKET myrpacket; 

myrpacket.flags.bits.packetType=2; 

packetType이 값을 사용할 수 있습니다 승인 유형 - 당신은 패킷 설정 PACKET_TYPE_ACK의 유형을 선택하려는 경우 예를 들어, 값 .. 을 변경?

비트, 바이트의 데이터이고, 상기 구조에서 선언으로 packetType은,이 바이트의 제 2 비트이다 그래서 원한다면

BYTE packetType  :2; 

설치 ackReq

myrpacket.flags.bits.ackReq=1; 

이 도움이되기를 바랍니다.

관련 문제