Code Tidy - Pastebin

New     Fork     Embed     View raw     Report

rssi-cpp - cpp

Embed

You can embed this paste into a blog or website with this code:

<iframe class="codetidy" type="text/html" width="100%" src="http://codetidy.com/paste/embed/913" frameborder="0"></iframe>

Add comment

Captcha
  1. #include "WProgram.h"?
  2. #include "rssi.h"?
  3. #include <SPI.h>?
  4. rssi::rssi()?
  5. {?
  6.   pinMode (10, OUTPUT);?
  7.     SPI.begin();?
  8.   SPI.setBitOrder(MSBFIRST); // Send most significant bit first when transferring a byte.?
  9.   SPI.setDataMode(SPI_MODE0); // Base value of clock is 0, data is captured on clock's rising edge.?
  10.   SPI.setClockDivider(SPI_CLOCK_DIV8); // Set SPI data rate to 16mhz/8. IE: 2mhz.?
  11.   }?
  12. // Reset Radio Module?
  13. void rssi::RADIO_Init(void){?
  14.   // Set Radio output pins?
  15.   pinMode(9,OUTPUT);?
  16.   pinMode(8,OUTPUT);?
  17.   // Reset the radio?
  18.   digitalWrite(8, HIGH);?
  19.   digitalWrite(9, HIGH);?
  20.   // Radio module initialization?
  21.   RADIO_Write(REG_CLOCK_MANUAL,0x41);?
  22.   RADIO_Write(REG_CLOCK_ENABLE,0x41);?
  23.   RADIO_Write(REG_ANALOG_CTL,0x44); ?
  24.   RADIO_Write(REG_CRYSTAL_ADJ,0x40);?
  25.   RADIO_Write(REG_VCO_CAL,0xC0);?
  26. }?
  27.  ?
  28.  ?
  29.  ?
  30. // Read data from radio module?
  31. unsigned char rssi::RADIO_Read(unsigned char address){?
  32.   digitalWrite(8, LOW);  // Enable module    ?
  33.   unsigned char value;?
  34.   SPI.transfer(address);?
  35.   value = SPI.transfer(0x00);?
  36.   digitalWrite(8, HIGH);// Disable module?
  37.  ?
  38.   return value;?
  39. }?
  40.  ?
  41.  ?
  42.  ?
  43. // Write data to radio module?
  44. void rssi::RADIO_Write(unsigned char address, unsigned char value){?
  45.   // Enable module?
  46.   digitalWrite(8, LOW);  // Enable module    ?
  47.   // Send data?
  48.   SPI.transfer(0x80|address);?
  49.   SPI.transfer(value);?
  50.   // Disable module?
  51.   digitalWrite(8, HIGH);?
  52. }?
  53.  ?
  54.  ?
  55.  ?
  56. // Returns RSSI (0..31) for given channel?
  57. unsigned char rssi::RADIO_RSSI(unsigned char channel){?
  58.   byte value;?
  59.   // Set channel?
  60.   RADIO_Write(REG_CHANNEL,channel);?
  61.   // Turn receiver on?
  62.   RADIO_Write(REG_CONTROL,0x80);?
  63.   // Wait to receiver start-up?
  64.   // SYNTH_SETTLE (200) + RECEIVER_READY (35) + RSSI_ADC_CONVERSION (50)?
  65.   delayMicroseconds(285);?
  66.   while(1){?
  67.     // Force conversion?
  68.     RADIO_Write(REG_CARRIER_DETECT,0x00);?
  69.     RADIO_Write(REG_CARRIER_DETECT,0x80);?
  70.     // RSSI_ADC_CONVERSION (50)?
  71.     delayMicroseconds(50);?
  72.     // Read RSSI?
  73.     value=RADIO_Read(REG_RSSI);?
  74.     // Exit if valid?
  75.     if (value&0x20) break;?
  76.   }?
  77.   // Turn receiver off?
  78.   RADIO_Write(REG_CONTROL,0x00);?
  79.   // Return lower 4 bits?
  80.   return (value&0x0F);?
  81. }?
© 2011 Code Tidy