Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Thomas EDERC 2010 5. Programming Tour.

Similar presentations


Presentation on theme: "1 Thomas EDERC 2010 5. Programming Tour."— Presentation transcript:

1 1 Thomas Watteyne @ EDERC 2010 5. Programming Tour

2 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 Watteyne @ EDERC 2010

3 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 Watteyne @ EDERC 2010

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

5 5 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

6 6 Interconnection Chip Select Clock SPI interface interrupts Thomas Watteyne @ EDERC 2010

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

8 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 Watteyne @ EDERC 2010

9 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 Watteyne @ EDERC 2010

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

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

12 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 Watteyne @ EDERC 2010

13 13 Operations on binary data A = 0b01101001 ~A = 0b10010110 A |= 0b00000010 => A=0b01101011 A &=~0b00001000 => A=0b01100001 A ^= 0b10001000 => A=0b11100001 A A=0b10100100 A>>2 => A=0b00011010 Thomas Watteyne @ EDERC 2010

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

15 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 Watteyne @ EDERC 2010

16 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 Watteyne @ EDERC 2010 lab1_led_loop

17 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 Watteyne @ EDERC 2010

18 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 Watteyne @ EDERC 2010 lab1_led_button

19 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 Watteyne @ EDERC 2010

20 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 Watteyne @ EDERC 2010 lab1_led_timer

21 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 Watteyne @ EDERC 2010

22 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 Watteyne @ EDERC 2010 lab2_txrx_simple

23 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 Watteyne @ EDERC 2010 lab2_txrx_simple

24 24 Continuous Transmission Thomas Watteyne @ EDERC 2010

25 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 Watteyne @ EDERC 2010 lab2_txrx_simple

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

27 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 Watteyne @ EDERC 2010

28 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 Watteyne @ EDERC 2010 lab2_txrx_chat

29 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 Watteyne @ EDERC 2010 lab2_txrx_chat

30 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 Watteyne @ EDERC 2010 lab2_txrx_chat

31 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 Watteyne @ EDERC 2010

32 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 bits99.9969% All other burst errors99.9984% Thomas Watteyne @ EDERC 2010

33 33 CRC: Cyclic Redundancy Check 11010011101100 1011 01100011101100 1011 0111011101100 1011 010111101100 1011 00001101100 1011 0001101100 1011 001101100 1011 01101100 1011 0110100 1011 011000 1011 01110 1011 0101 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 Watteyne @ EDERC 2010

34 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 Watteyne @ EDERC 2010 lab4_crc

35 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 { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/13/3890958/slides/slide_35.jpg", "name": "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

36 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 Watteyne @ EDERC 2010 lab4_crc

37 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 Watteyne @ EDERC 2010

38 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 Watteyne @ EDERC 2010 lab3_spectrum_ analyzer

39 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 Watteyne @ EDERC 2010 lab3_spectrum_ analyzer

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

41 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 Watteyne @ EDERC 2010

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

43 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[] = {" 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); } e.g. “-55 0.75” Prepare string transmit string over serial lab4_pdr Thomas Watteyne @ EDERC 2010

44 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 Watteyne @ EDERC 2010 lab4_pdr

45 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 Watteyne @ EDERC 2010 lab4_pdr

46 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 Watteyne @ EDERC 2010 lab4_pdr

47 47 Wonderful Wireless Waterfall pdr_vs_rssi.py Thomas Watteyne @ EDERC 2010

48 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 Watteyne @ EDERC 2010

49 49 Thomas Watteyne @ EDERC 2010 5.9 Conclusions

50 50 Conclusions A building block approach – Blinking LEDs – Interacting with button – Measuring time – Interacting with the serial port – Sending/receiving packets More? – http://wsn.eecs.berkeley.edu/svn/ezwsn/ http://wsn.eecs.berkeley.edu/svn/ezwsn/ – http://cnx.org/content/col10684/latest/ http://cnx.org/content/col10684/latest/ – http://openwsn.berkeley.edu/ http://openwsn.berkeley.edu/ Contribute! – watteyne@eecs.berkeley.edu watteyne@eecs.berkeley.edu Thomas Watteyne @ EDERC 2010


Download ppt "1 Thomas EDERC 2010 5. Programming Tour."

Similar presentations


Ads by Google