1 Thomas EDERC 2010 5. Programming Tour.

Slides:



Advertisements
Similar presentations
Lab 1 I/O, timers, interrupts on the eZ430-RF2500 Thomas Watteyne EE290Q – Spring 2010
Advertisements

Serial Communications (Chapter 10)
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
Confidentiality/date line: 13pt Arial Regular, white Maximum length: 1 line Information separated by vertical strokes, with two spaces on either side Disclaimer.
LAB 6: Serial Communication
Notes on the ez430-RF2500. Sources
USART and Asynchrono us Communica tion The USART is used for synchronous and asynchronous serial communication. USART = Universal Synchronous/Asynchronous.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Railway Foundation Electronic, Electrical and Processor Engineering.
CS4101 嵌入式系統概論 Software UART Revisited Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan ( Materials from MSP430.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Chung-Ta King National Tsing Hua University
MSP432™ MCUs Training Part 5: Digital Peripherals
LAB 7: WDT+ and Low-Power Optimization
1 © Unitec New Zealand Embedded Hardware ETEC 6416 Date: - 10 Aug,2011.
Lecture 18: ADC Implementation Lecturers: Professor John Devlin.
MCRDS Data Format May 3, File Type Header Data file type –32 byte string (“Data-MCRDS”) terminated with null character ‘\0’. Characters after termination.
1 4-Integrating Peripherals in Embedded Systems. 2 Introduction Single-purpose processors  Performs specific computation task  Custom single-purpose.
Lecture Set 9 MCS-51 Serial Port.
Lab 5 System Design Thomas Watteyne EE290Q – Spring 2010
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Lecturers: Professor John Devlin Mr Robert Ross
Arch1 LCD Lab Eric Freudenthal. Topics Score Demo LCD Panel Geometry Utilities to draw to the display Drawing characters Buttons Nuisance: multiple versions.
Advanced Microprocessor1 I/O Interface Programmable Interval Timer: 8254 Three independent 16-bit programmable counters (timers). Each capable in counting.
NS Training Hardware. Serial Controller - UART.
Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010
Universal Asynchronous Receiver/Transmitter (UART)
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
EA PROJETO EM ELETRÔNICA APLICADA Bruno Mourão Siqueira.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Microcontrollers JULES CALELLA. Microcontrollers vs Microprocessors  Microprocessors – do not contain RAM, ROM, I/O  Microcontrollers – The whole package.
Low Power Sensor Node Design with MSP430 + CC2520 YoonMo Yeon
UNIT 2. CPUXV2 20-bit addressing User-definable Boot Strap Loader RAM starts at 0x1C00 Beginning of MAIN flash moves according to RAM Vector table starts.
Lab 4 CRC, PDR vs. distance, preamble sampling Thomas Watteyne EE290Q – Spring 2010
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Chip Config & Drivers – Required Drivers:
Embedded Microcontroller Systems
Introduction to MSP430G2553 and MPU6050
Introduction Why low power?
Introduction Why low power?
CS4101 嵌入式系統概論 General Purpose IO
ECE 382 Lesson 15 Lesson Outline S/W Delays Wrap up
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 嵌入式系統概論 Serial Communication
EMBEDDED SYSTEMS UNIT 4.
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Lesson Outline Interrupts Admin Assignment #9 due next lesson
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
Embedded Microcontroller Systems
Chapter 6 General Purpose Input/Output
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
4-Integrating Peripherals in Embedded Systems
Prof. Chung-Ta King Department of Computer Science
4-Integrating Peripherals in Embedded Systems
CS4101 嵌入式系統概論 General Purpose IO
Subject Name: Microcontroller Subject Code: 10ES42
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
Lecture 9: TI MSP430 Interrupts & Low Power Modes
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
ECE 3567 Microcontroller Lab
Presentation transcript:

1 Thomas EDERC Programming Tour

2 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

3 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

4 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 EDERC 2010

5 CC2500 Any frequency on the GHz band – Not 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 EDERC 2010

6 Interconnection Chip Select Clock SPI interface interrupts Thomas EDERC 2010

7 eZ430-RF LEDs pushbutton CC2500 chip antenna 26MHz crystal for radio extension ports MSP430 USB programmer: Power Debug (JTAG) Interface (serial) Thomas EDERC 2010

8 Extension Pins P1: GND P2: VCC_EXT P3: P2.0I/O, ACLK, OA010 P4: P2.1I/O, Timer_A3.INCLK, SMCLK, OA0O P5: P2.2I/O, Timer_A3.CCI0B, Timer_A3.TA0, OA P6: P2.3I/O, Timer_A3.CCI1B, Timer_A3.TA1, OA P7: P2.4I/O, Timer_A3.TA2, OA P8: P4.3I/O, Timer_B3.CCI0B, Timer_B3.TB0, OA P9: P4.4I/O, Timer_B3.CCI1B, Timer_B3.TB1, OA P10: P4.5I/O, Timer_B3.TB2, OA P11: P4.6I/O, OA P12: GND P13: GDO0I/O from the CC2500 (configurable) P14: GDO2I/O from the CC2500 (configurable) P15: P3.2I/O, UC1SOMI P16: P3.3I/O, UC1CLK P17: P3.0I/O P18: P3.1I/O, UC1SIMO Thomas EDERC 2010

9 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

10 IAR Embedded Workbench project file navigator compile open files Thomas EDERC 2010

11 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 EDERC 2010

12 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

13 Operations on binary data A = 0b ~A = 0b A |= 0b => A=0b A &=~0b => A=0b A ^= 0b => A=0b A A=0b A>>2 => A=0b Thomas EDERC 2010

14 I/O port registers P1DIR: direction, 0=in, 1=out P1OUT: set output P1IN: read input Thomas EDERC 2010

15 A steady LED lab1_led_steady Disable watchdog timer P1.0 and P1.1 as output P1.0=1 and P1.1=1 Continue executing #include "io430.h" #include "in430.h" int main( void ) { WDTCTL = WDTPW + WDTHOLD; P1DIR |= 0x03; P1OUT |= 0x03; while(1); } Thomas EDERC 2010

16 Active Waiting Loop #include "io430.h" #include "in430.h" int main( void ) { WDTCTL = WDTPW + WDTHOLD; int i; P1DIR |= 0x03; while (1) { P1OUT ^= 0x03; for (i=0;i<10000;i++) { __no_operation(); } P1.0 and P1.1 as output Change Led state (aka toggle) Thomas EDERC 2010 lab1_led_loop

17 Interrupt Interrupt only when both – General interrupt enabled in status register – Specific interrupt enabled in specific register Interrupt Service Routine written as: #pragma vector=TIMERA0_VECTOR ISR sometimes needs to clear an interrupt flag in a specific register Thomas EDERC 2010

18 Button-Driven Toggle Through Interrupts #include "io430.h" #include "in430.h" int main( void ) { WDTCTL = WDTPW + WDTHOLD; P1DIR |= 0x03; P1DIR &= ~0x04; P1REN |= 0x04; P1OUT |= 0x04; P1IE |= 0x04; __bis_SR_register(GIE); while(1); } #pragma vector=PORT1_VECTOR __interrupt void Port_1 (void) { P1IFG &= ~0x04; P1OUT ^= 0x03; } P1.2 as input enable resistor (for button) enable interrupt for P1.2 globally enable interrupts (do this last) Executed when interrupt from P1 Actual function name has no importance Clear interrupt flag (mandatory) Toggle LEDs Thomas EDERC 2010 lab1_led_button

19 Timer A timer is a counter which – Counts in a certain way (up, down, continuous) – At every clock tick Can be used in two ways: – Triggers interrupts when reaching a given value (compare mode) or – Records its timer value on other interrupts (capture mode) Thomas EDERC 2010

20 Timer-Driven Toggle Through Timer Interrupts #include "io430.h" #include "in430.h" int main( void ) { WDTCTL = WDTPW + WDTHOLD; P1DIR |= 0x03; TACCTL0 = CCIE; TACCR0 = 1000; TACTL = TASSEL_1 + MC_1; __bis_SR_register(GIE+LPM3_bits); } #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { P1OUT ^= 0x03; } Timer_A interrupt enable Capture Compare to 1000 Count following ACLK Count in up mode interrupt Globally enable interrupt low power mode, waiting for interrupts Executed at each Timer_A interrupt Thomas EDERC 2010 lab1_led_timer

21 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

22 Simple Tx/Rx #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; } Init MSP430 (clock, leds, button) Init CC2500 (pins, SPI, registers) Start CC2500 oscill. (IDLE state) CC2500 to RX state low power mode, waiting for interrupts Executed when packet received (“meta” interrupt declaration) Executed when button pushed clear button interrupt flag declare packet w. max length declare useful length copy to cc2500 TXFIFO and send Length (1B)Source (4B)Destination (4B)Payload (Length-8 bytes long) Thomas EDERC 2010 lab2_txrx_simple

23 #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; } Change Channel #include "radios/family1/mrfi_spi.h" mrfiSpiWriteReg(CHANNR,0x10); Removing this line cause continuous transmissions Thomas EDERC 2010 lab2_txrx_simple

24 Continuous Transmission Thomas EDERC 2010

25 #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; } Change Transmission Power #include "radios/family1/mrfi_spi.h" mrfiSpiWriteReg(PATABLE,0xFF); Thomas EDERC 2010 lab2_txrx_simple

26 Impact of Transmission Power settingpowercurrent 0X84-24dBm16.1mA 0x55-16dBm16.5mA 0x97-10dBm18.3mA 0xA9-4dBm22.6mA 0xFE0dBm27.6mA 0xFF1dBm27.9mA Thomas EDERC 2010

27 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

28 Wireless Chat [1/3] #include "radios/family1/mrfi_spi.h" #include "mrfi.h" uint8_t index_output = 9; mrfiPacket_t packetToSend; 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); } Enable UART Thomas EDERC 2010 lab2_txrx_chat

29 Wireless Chat [2/3] 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)); } when received a packet Copy RXFIFO into “packet” write over serial port newline (for PuTTY) Thomas EDERC 2010 lab2_txrx_chat

30 Wireless Chat [3/3] #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); } when received one character over serial port copy serial input buffer to “rx” Append to the packet being constructed newline or packet full copy to TXFIFO, trigger Tx re-initialize echo over serial port Thomas EDERC 2010 lab2_txrx_chat

31 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

32 CRC: Cyclic Redundancy Check If PKTCTRL0.CRC_EN=1: – At Tx, data is hashed and result append to the packet as a 2-byte field – At Rx, data is hashed and result compared to CRC field, packet dropped if fails How CRC works – Calculate the remainder of a (binary) division – In CC2500, CRC-16-IBM (x 16 + x 15 + x 2 + 1) Single bit errors100% Double-bit errors100% Odd-Numbered errors100% Burst Errors Shorter than 16 bits100% Burst Errors of exactly 17 bits % All other burst errors % Thomas EDERC 2010

33 CRC: Cyclic Redundancy Check Pick a CRC length – e.g. 3 bits Pick a polynom – e.g. x 4 +x+1 (1011) – (Always a leftmost 1!) While bits in data – Write under leftmost data bits – iif leftmost data bit is 1, XOR (leftmost bit always turns to 0) – Shift right one place Collect 3-bit CRC Thomas EDERC 2010

34 The Importance of CRC [1/3] #include "radios/family1/mrfi_spi.h" #include "mrfi.h" mrfiPacket_t packetToSend; int main(void) { BSP_Init(); P1REN |= 0x04; P1OUT |= 0x04; P1IE |= 0x04; MRFI_Init(); mrfiSpiWriteReg(PATABLE,0xBB); mrfiSpiWriteReg(PKTCTRL0,0x41); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); MRFI_RxOn(); __bis_SR_register(GIE+LPM4_bits); } Enable UART reduce the Tx Power for more frequent errors disable CRC Thomas EDERC 2010 lab4_crc

35 The Importance of CRC [2/3] void MRFI_RxCompleteISR() { uint8_t i; P1OUT ^= 0x02; mrfiPacket_t packet; MRFI_Receive(&packet); char output[] = {" \r\n"}; for (i=9;i<packet.frame[0];i++) { output[i-9]=packet.frame[i]; } TXString(output, (sizeof output)); } when receiving a packet Copy RXFIFO to “packet” format string send string over serial Thomas EDERC 2010 lab4_crc

36 The Importance of CRC [3/3] #pragma vector=PORT1_VECTOR __interrupt void Port_1 (void) { P1IFG &= ~0x04; char character = 'a'; uint8_t index; mrfiPacket_t packet; for (index=9;index<30;index++) { packet.frame[index]=character++; } packet.frame[0]=++index; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); P1OUT ^= 0x01; } when button is pressed comment out for continuous Tx Fill frame with ‘abcdef…’ Copy to TXFIFO and send Thomas EDERC 2010 lab4_crc

37 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

38 Poor Man’s Spectrum Analyzer [1/2] #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() { } prints out a signed int as characters send string over serial we’re not interested in actually receiving packets Thomas EDERC 2010 lab3_spectrum_ analyzer

39 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); } Poor Man’s Spectrum Analyzer [2/2] change channel Enable UART switch radio on read current noise level Thomas EDERC 2010 lab3_spectrum_ analyzer

40 Poor Man’s Spectrum Analyzer spectrum.py Thomas EDERC 2010

41 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

42 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 EDERC 2010

43 Wonderful Wireless Waterfall [1/4] #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[] = {" \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); } e.g. “ ” Prepare string transmit string over serial lab4_pdr Thomas EDERC 2010

44 Wonderful Wireless Waterfall [2/4] 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); } when button is pressed enable serial communication Wait for interrupts in low power mode Thomas EDERC 2010 lab4_pdr

45 Wonderful Wireless Waterfall [3/4] 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]; } When I receive a packet Thomas EDERC 2010 lab4_pdr

46 Wonderful Wireless Waterfall [4/4] #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); } when button is pressed Thomas EDERC 2010 lab4_pdr

47 Wonderful Wireless Waterfall pdr_vs_rssi.py Thomas EDERC 2010

48 Section 5 - Overview 5. Programming Tour 5.1Crash-course on the Hardware 5.2Development Environment 5.3Blinking the LEDs 5.4Enabling Wireless 5.5Wireless Chat 5.6The Importance of CRC 5.7Poor Man’s Spectrum Analyzer 5.8Wonderful Wireless Waterfall Thomas EDERC 2010

49 Thomas EDERC Conclusions

50 Conclusions A building block approach – Blinking LEDs – Interacting with button – Measuring time – Interacting with the serial port – Sending/receiving packets More? – – – Contribute! – Thomas EDERC 2010