370 likes | 539 Views
5. Programming Tour. Section 5 - Overview. 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer
E N D
5. Programming Tour Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
MSP430 • “Heart” of the eZ430-RF2500 • 16-bit 16MHz RISC • 32kB ROM, 1kB RAM • 2 Timers, USCI, 10-bit ADCs • Debug capabilities using JTAG • Low Power Operation Thomas Watteyne @ EDERC 2010
CC2500 • Any frequency on the 2.4-2.485GHz band • Not 802.15.4-compliant • Wake-on-radio support • Preamble sampling in hardware • 47 configuration registers • Switch Tx/Rx/idle • TXBUF, RXBUF • Tx power and frequency • Follows a state machine SmartRF Studio Thomas Watteyne @ EDERC 2010
Interconnection Chip Select Clock SPI interface interrupts Thomas Watteyne @ EDERC 2010
eZ430-RF2500 2 LEDs • USB programmer: • Power • Debug (JTAG) • Interface (serial) pushbutton MSP430 CC2500 26MHz crystal for radio extension ports chip antenna Thomas Watteyne @ EDERC 2010
Extension Pins • P1: GND • P2: VCC_EXT • P3: P2.0 I/O, ACLK, OA010 • P4: P2.1 I/O, Timer_A3.INCLK, SMCLK, OA0O • P5: P2.2 I/O, Timer_A3.CCI0B, Timer_A3.TA0, OA • P6: P2.3 I/O, Timer_A3.CCI1B, Timer_A3.TA1, OA • P7: P2.4 I/O, Timer_A3.TA2, OA • P8: P4.3 I/O, Timer_B3.CCI0B, Timer_B3.TB0, OA • P9: P4.4 I/O, Timer_B3.CCI1B, Timer_B3.TB1, OA • P10: P4.5 I/O, Timer_B3.TB2, OA • P11: P4.6 I/O, OA • P12: GND • P13: GDO0 I/O from the CC2500 (configurable) • P14: GDO2 I/O from the CC2500 (configurable) • P15: P3.2 I/O, UC1SOMI • P16: P3.3 I/O, UC1CLK • P17: P3.0 I/O • P18: P3.1 I/O, UC1SIMO Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
IAR Embedded Workbench open files project file navigator compile Thomas Watteyne @ EDERC 2010
Talking with your mote over “USB” • Use Windows Device Manager to idenfify the COM port the eZ430-RF2500 is on • Use PuTTY to connect to that port Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
Operations on binary data • A = 0b01101001 • ~A = 0b10010110 • A |= 0b00000010 => A=0b01101011 • A &=~0b00001000 => A=0b01100001 • A ^= 0b10001000 => A=0b11100001 • A<<2 => A=0b10100100 • A>>2 => A=0b00011010 Thomas Watteyne @ EDERC 2010
I/O port registers • P1DIR: direction, 0=in, 1=out • P1OUT: set output • P1IN: read input Thomas Watteyne @ EDERC 2010
Active Waiting Loop P1.0 and P1.1 as output Change Led state (aka toggle) lab1_led_loop #include "io430.h" #include "in430.h" int main( void ) { WDTCTL = WDTPW + WDTHOLD; inti; P1DIR |= 0x03; while (1) { P1OUT ^= 0x03; for (i=0;i<10000;i++) { __no_operation(); } } } Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
Simple Tx/Rx Init MSP430 (clock, leds, button) Init CC2500 (pins, SPI, registers) CC2500 to RX state Start CC2500 oscill. (IDLE state) low power mode, waiting for interrupts Executed when packet received (“meta” interrupt declaration) Executed when button pushed clear button interrupt flag copy to cc2500 TXFIFO and send declare packet w. max length declare useful length lab2_txrx_simple #include "mrfi.h" int main(void) { BSP_Init(); P1REN |= 0x04; P1OUT |= 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; } Thomas Watteyne @ EDERC 2010
Change Channel #include "radios/family1/mrfi_spi.h" mrfiSpiWriteReg(CHANNR,0x10); Removing this line cause continuous transmissions lab2_txrx_simple #include "mrfi.h" int main(void) { BSP_Init(); P1REN |= 0x04; P1OUT |= 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; } Thomas Watteyne @ EDERC 2010
Continuous Transmission Thomas Watteyne @ EDERC 2010
Change Transmission Power #include "radios/family1/mrfi_spi.h" mrfiSpiWriteReg(PATABLE,0xFF); lab2_txrx_simple #include "mrfi.h" int main(void) { BSP_Init(); P1REN |= 0x04; P1OUT |= 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; } Thomas Watteyne @ EDERC 2010
Impact of Transmission Power Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
Wireless Chat [1/3] Enable UART lab2_txrx_chat #include "radios/family1/mrfi_spi.h" #include "mrfi.h" uint8_t index_output = 9; mrfiPacket_tpacketToSend; int main(void) { BSP_Init(); MRFI_Init(); P3SEL |= 0x30; // P3.4,5 = USCI_A0 TXD/RXD UCA0CTL1 = UCSSEL_2; // SMCLK UCA0BR0 = 0x41; // 9600 from 8Mhz UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt MRFI_WakeUp(); MRFI_RxOn(); index_output=0; __bis_SR_register(GIE+LPM4_bits); } Thomas Watteyne @ EDERC 2010
Wireless Chat [2/3] when received a packet Copy RXFIFO into “packet” newline(for PuTTY) write over serial port lab2_txrx_chat void MRFI_RxCompleteISR() { uint8_t i; P1OUT ^= 0x02; mrfiPacket_t packet; MRFI_Receive(&packet); char output[] = {" "}; for (i=9;i<29;i++) { output[i-9]=packet.frame[i]; if (packet.frame[i]=='\r') { output[i-9]='\n'; output[i-8]='\r'; } } TXString(output, (sizeof output)); } Thomas Watteyne @ EDERC 2010
Wireless Chat [3/3] copy serial input buffer to “rx” when received one character over serial port Append to the packet being constructed newline or packet full copy to TXFIFO, trigger Tx re-initialize echo over serial port lab2_txrx_chat #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { char rx = UCA0RXBUF; uint8_t i; packetToSend.frame[index_output]=rx; index_output++; if (rx=='\r' || index_output==29) { packetToSend.frame[0]=28; MRFI_Transmit(&packetToSend, MRFI_TX_TYPE_FORCED); index_output = 9; for(i=9;i<29;i++) { packetToSend.frame[i]=' '; } P1OUT ^= 0x01; } P1OUT ^= 0x02; TXString(&rx, 1); } Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
Poor Man’s Spectrum Analyzer [1/2] prints out a signed int as characters send string over serial we’re not interested in actually receiving packets lab3_spectrum_analyzer #include "mrfi.h" #include "radios/family1/mrfi_spi.h" void print_rssi(int8_t rssi) { char output[] = {" 000 "}; if (rssi<0) {output[0]='-';rssi=-rssi;} output[1] = '0'+((rssi/100)%10); output[2] = '0'+((rssi/10)%10); output[3] = '0'+ (rssi%10); TXString(output, (sizeof output)-1); } void MRFI_RxCompleteISR() { } Thomas Watteyne @ EDERC 2010
Poor Man’s Spectrum Analyzer [2/2] change channel read current noise level Enable UART switch radio on lab3_spectrum_analyzer int main(void) { int8_t rssi; uint8_t channel; BSP_Init(); MRFI_Init(); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); __bis_SR_register(GIE); while(1) { for (channel=0;channel<200;channel++) { MRFI_RxIdle(); mrfiSpiWriteReg(CHANNR,channel); MRFI_RxOn(); rssi=MRFI_Rssi(); print_rssi(rssi); } TXString("\n",1); } } Thomas Watteyne @ EDERC 2010
Poor Man’s Spectrum Analyzer spectrum.py Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010
Wonderful Wireless Waterfall • Receiver listens • When button pressed sender sends a burst of packets • 100 packets with counter from 1 to 100 • 20 packets with counter to 101 • When receiving a packet • If packet counter <101, increment a counter and store the RSSI • For the first packet with counter==101, display “average RSSI – channel success probability” Thomas Watteyne @ EDERC 2010
Wonderful Wireless Waterfall [1/4] e.g. “-55 0.75” Prepare string transmit string over serial lab4_pdr #include "mrfi.h" uint8_t counter, num_received, bool_counting; int16_t cumulative_rssi; mrfiPacket_t packet; void print_probability(int16_t cumulative_rssi, uint8_t number) { char output[] = {" 000 0.00\n"}; if (cumulative_rssi<0) { output[0]='-'; cumulative_rssi=-cumulative_rssi; } output[1] = '0'+((cumulative_rssi/100)%10); output[2] = '0'+((cumulative_rssi/10)%10); output[3] = '0'+ (cumulative_rssi%10); output[5] = '0'+((number/100)%10); output[7] = '0'+((number/10)%10); output[8] = '0'+ (number%10); TXString(output, (sizeof output)-1); } Thomas Watteyne @ EDERC 2010
Wonderful Wireless Waterfall [2/4] when button is pressed enable serial communication Wait for interrupts in low power mode lab4_pdr int main(void) { BSP_Init(); P1REN |= 0x04; P1IE |= 0x04; MRFI_Init(); mrfiSpiWriteReg(PATABLE,0x50); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); MRFI_RxOn(); __bis_SR_register(GIE+LPM4_bits); } Thomas Watteyne @ EDERC 2010
Wonderful Wireless Waterfall [3/4] When I receive a packet lab4_pdr void MRFI_RxCompleteISR() { P1OUT ^= 0x02; MRFI_Receive(&packet); counter = packet.frame[9]; if (counter==101) { if (bool_counting == 1) { print_probability(cumulative_rssi/num_received,num_received); } bool_counting=0; num_received=0; cumulative_rssi=0; } else { bool_counting=1; num_received++; cumulative_rssi+=(int8_t) packet.rxMetrics[0]; } } Thomas Watteyne @ EDERC 2010
Wonderful Wireless Waterfall [4/4] when button is pressed lab4_pdr #pragma vector=PORT1_VECTOR __interrupt void interrupt_button (void) { P1IFG &= ~0x04; P1OUT ^= 0x01; mrfiPacket_t packet; packet.frame[0]=8+3; for (counter=1;counter<101;counter++){ packet.frame[9]=counter; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); } for (counter=0;counter<20;counter++){ packet.frame[9]=101; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); } } Thomas Watteyne @ EDERC 2010
Wonderful Wireless Waterfall pdr_vs_rssi.py Thomas Watteyne @ EDERC 2010
Section 5 - Overview 5. Programming Tour 5.1 Crash-course on the Hardware 5.2 Development Environment 5.3 Blinking the LEDs 5.4 Enabling Wireless 5.5 Wireless Chat 5.6 The Importance of CRC 5.7 Poor Man’s Spectrum Analyzer 5.8 Wonderful Wireless Waterfall Thomas Watteyne @ EDERC 2010