<< Chapter < Page | Chapter >> Page > |
source_code/iar_v4.11/lab_ezwsn.eww
with IAR. The project corresponding to this section is called
txrx_simple
. .#include "mrfi.h"
#include "radios/family1/mrfi_spi.h"int main(void)
{BSP_Init();
P1REN |= 0x04;P1IE |= 0x04;
MRFI_Init();MRFI_WakeUp();
MRFI_RxOn();__bis_SR_register(GIE+LPM4_bits);
}void MRFI_RxCompleteISR()
{P1OUT ^= 0x02;
}#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void){
P1IFG&= ~0x04;
mrfiPacket_t packet;packet.frame[0]=8+20;MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);
P1OUT ^= 0x01;}
The simplest Tx/Rx example possible
The packet format is:
Length (1B) | Source (4B) | Destination (4B) | Payload (Length-8 bytes long) |
RSSI (1B) | CRC (1b) | LQI (1b) |
A variable of type
mrfiPacket_t
is a structure containing two parts:
packet.frame
is the frame to be transmitted. The first byte is the
Length
of the payload together with source and destination Address. With the current
driver implementation, addresses are coded on 4 bytes, and the maximumPayload length is 20 bytes. By default, the CC2500 does not perform address
filtering, so in practice we will not care about the values of the address fields.packet.rxMetrics
are statistics on the last received packet, i.e. it only
makes sense on received packet. The first byte is the Received Signal StrengthIndicator (
RSSI ) at sync word detection. This is the signal level in dBm. The
next bit indicates whether the Cyclic Redundancy Check (
CRC ) was successful
(by default, the CC2500 is configured to reject packets with unsuccessful CRCcheck, so in practice this field will always be 1). The last 7 bits are the Link Quality
Indicator (
LQI ). The LQI gives an estimate of how easily a received signal
can be demodulated by accumulating the magnitude of the error between idealconstellations and the received signal over the 64 symbols immediately following
the sync word.Some keys for understanding the code:
Go to
definition of "BSP_Init()"
if you want to know) which disables the
watchdog, initializes the MCLK at 8MHz, sets LED ports as outputs and thebutton port as input. Note that it does neither enables the internal resistor of the
button, nor enables interrupts. This is done on lines 5 and 6.MRFI_Init()
initializes the 6 wires between the MSP430 and the CC2500, powers-up the CC2500 and configures the CC2500 47 registers and turns on interrupts from the CC2500;MRFI_RxCompleteISR
is called
Note that the real interrupt function with the usual
#pragma
declaration is hidden in
the drivers .The CC2500 can transmit at any frequency on the
ISM band
2400.0-2483.5 MHz .
The chip divides the 2400.0-2483.5 MHz spectrum into
channels separated by a
tunable
channel spacing . By default, channel spacing is 200kHz; with default
configuration, channel 0 is 2433.0Mhz, channel 1 is 2433.2Mhz, and so forth. Thechannel is configured through the
CHANNR
register of the CC2500.
#include "radios/family1/mrfi_spi.h"
MRFI_Init();
. You may replace
0x10
by the frequency you have chosen. This programs the
CHANNR
register of the CC2500. Be aware that values
above
0xFC
are prohibited because the corresponding frequency is above 2483.5
MHz:
mrfiSpiWriteReg(CHANNR,0x10);
When you have reprogrammed both boards, you should be able to communicatewithout interference.
Notification Switch
Would you like to follow the 'Ezwsn: experimenting with wireless sensor networks using the ez430-rf2500' conversation and receive update notifications?