lab 2 energy consumption, wireless chat thomas watteyne ee290q – spring 2010

9
Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010 http://wsn.eecs.berkeley.edu/290Q

Upload: joseph-morrison

Post on 03-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

Lab 2energy consumption,

wireless chat

Thomas WatteyneEE290Q – Spring 2010

http://wsn.eecs.berkeley.edu/290Q

Page 2: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

2

Simple Tx/Rx

txrx_simple

#include "mrfi.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;}

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)

Page 3: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

3

Change Channel

txrx_simple

#include "mrfi.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;}

#include "radios/family1/mrfi_spi.h"

mrfiSpiWriteReg(CHANNR,0x10);

Removing this line cause continuous

transmissions

Page 4: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

4

Continuous Transmission

Page 5: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

5

Change Transmission Power

txrx_simple

#include "mrfi.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;}

#include "radios/family1/mrfi_spi.h"

mrfiSpiWriteReg(PATABLE,0xFF);

Page 6: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

6

Impact of Transmission Power

setting power current

0X84 -24dBm 16.1mA

0x55 -16dBm 16.5mA

0x97 -10dBm 18.3mA

0xA9 -4dBm 22.6mA

0xFE 0dBm 27.6mA

0xFF 1dBm 27.9mA

Page 7: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

7

Wireless Chat [1/3]

txrx_chat

#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

Page 8: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

8

Wireless Chat [2/3]

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));}

when received a packet

Copy RXFIFO into “packet”

write over serial portnewline(for PuTTY)

Page 9: Lab 2 energy consumption, wireless chat Thomas Watteyne EE290Q – Spring 2010

9

Wireless Chat [3/3]

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);}

when received one character

over serial port

copy serial input buffer to “rx”

Append to the packet being constructed

newline or packet fullcopy to TXFIFO,

trigger Tx

re-initialize

echo over serial port