Wixel SDK
radio_registers.c
1 #include <radio_registers.h>
2 #include <cc2511_map.h>
3 
5 {
6  // Transmit power: one of the highest settings, but not the highest.
7  PA_TABLE0 = 0xFE;
8 
9  // Set the center frequency of channel 0 to 2403.47 MHz.
10  // Freq = 24/2^16*(FREQ[23:0]) = 24/2^16*(0x642500) = 2403.47 MHz
11  FREQ2 = 0x64;
12  FREQ1 = 0x25;
13  FREQ0 = 0x00;
14 
15  // Note: We had to modify MDMCFG1 from the settings given by
16  // SmartRF Studio to be compatible with the datasheet.
17  // (NUM_PREAMBLE should be 8 at 500 kbps and having it be high is a good idea in general).
18  // MDMCFG1.FEC_EN = 0 : Disable Forward Error Correction
19  // MDMCFG1.NUM_PREAMBLE = 100 : Minimum number of preamble bytes is 8.
20  // MDMCFG1.CHANSPC_E = 11 : Channel spacing exponent.
21  // MDMCFG0.CHANSPC_M = 0x87 : Channel spacing mantissa.
22  // Channel spacing = (256 + CHANSPC_M)*2^(CHANSPC_E) * f_ref / 2^18
23  // So the center of channel 255 is
24  // 2403.47 + 255 * ((256 + 0x87)*2^(3) * 24/2^18) = 2476.50 MHz
25  // NOTE: The radio's Forward Error Correction feature requires CLKSPD=000.
26  MDMCFG1 = 0x43;
27  MDMCFG0 = 0x87; // Modem Configuration
28 
29  // Controls the FREQ_IF used for RX.
30  // This is affected by MDMCFG2.DEM_DCFILT_OFF according to p.212 of datasheet.
31  FSCTRL1 = 0x0A; // Frequency Synthesizer Control
32  FSCTRL0 = 0x00; // Frequency Synthesizer Control
33 
34  // Sets the data rate (symbol rate) used in TX and RX. See Sec 13.5 of the datasheet.
35  // Also sets the channel bandwidth.
36  // We tried different data rates: 375 kbps was pretty good, but 400 kbps and above caused lots of packet errors.
37  // NOTE: If you change this, you must change RSSI_OFFSET in radio_registers.h
38  MDMCFG4 = 0x1D; MDMCFG3 = 0xDE; // Modem configuration (data rate = 350 kbps, bandwidth = 600 kHz).
39 
40  // MDMCFG2.DEM_DCFILT_OFF = 0, enable digital DC blocking filter before
41  // demodulator. This affects the FREQ_IF according to p.212 of datasheet.
42  // MDMCFC2.MANCHESTER_EN = 0 is required because we are using MSK (see Sec 13.9.2)
43  // MDMCFG2.MOD_FORMAT = 111: MSK modulation
44  // MDMCFG2.SYNC_MODE = 111: Strictest requirements for receiving a packet.
45  MDMCFG2 = 0x73; // Modem Configuration
46 
47  //DEVIATN = 0x00; // Modem Deviation Setting. No effect because we are using MSK.
48  // See Sec 13.9.2.
49 
50  FREND1 = 0xB6; // Front End RX Configuration (adjusts various things, not well documented)
51  FREND0 = 0x10; // Front End TX Configuration (adjusts current TX LO buffer, not well documented)
52 
53  // F0CFG and BSCFG configure details of the PID loop used to correct the
54  // bit rate and frequency of the signal (RX only I believe).
55  FOCCFG = 0x1D; // Frequency Offset Compensation Configuration
56  BSCFG = 0x1C; // Bit Synchronization Configuration
57 
58  // AGC Control:
59  // This affects many things, including:
60  // Carrier Sense Absolute Threshold (Sec 13.10.5).
61  // Carrier Sense Relative Threshold (Sec 13.10.6).
62  AGCCTRL2 = 0xC7;
63  AGCCTRL1 = 0x00;
64  AGCCTRL0 = 0xB2;
65 
66  // Frequency Synthesizer registers that are not fully documented.
67  FSCAL3 = 0xEA;
68  FSCAL2 = 0x0A;
69  FSCAL1 = 0x00;
70  FSCAL0 = 0x11;
71 
72  // Mostly-undocumented test settings.
73  // NOTE: The datasheet says TEST1 must be 0x31, but SmartRF Studio recommends 0x11.
74  TEST2 = 0x88;
75  TEST1 = 0x31;//0x31;//0x11;
76  TEST0 = 0x09;//0x09;//0x0B;
77 
78  // Packet control settings.
79  PKTCTRL1 = 0x04;
80  PKTCTRL0 = 0x45; // Enable data whitening, CRC, and variable length packets.
81 }
82 
84 {
85  return (LQI & 0x80) ? 1 : 0;
86 }
87 
89 {
90  return LQI & 0x7F;
91 }
92 
94 {
95  return ((int8)RSSI)/2 - RSSI_OFFSET;
96 }
#define RSSI_OFFSET
void radioRegistersInit()
__bit BIT
Definition: cc2511_types.h:32
uint8 radioLqi()
unsigned char uint8
Definition: cc2511_types.h:9
BIT radioCrcPassed()
int8 radioRssi()
signed char int8
Definition: cc2511_types.h:12