RSSI Measurements

Code 1

#include "contiki.h"
#include "net/rime.h"
#include "net/netstack.h"

#include "dev/leds.h"
#include "dev/cc2420.h"
#include "dev/cc2420_const.h"
#include "dev/spi.h"
#include <stdio.h>

/*---------------------------------------------------------------------------*/
/* This assumes that the CC2420 is always on and "stable" */
static void
set_frq(int c)
{
  int f;
  /* fine graied channel - can we even read other channels with CC2420 ? */
  f = c + 302 + 0x4000;

  CC2420_WRITE_REG(CC2420_FSCTRL, f);
  CC2420_STROBE(CC2420_SRXON);
}

static void
do_rssi(void)
{
  int channel;
  printf("RSSI:");
  for(channel = 0; channel <= 79; ++channel) {
    set_frq(channel + 55);
    printf("%d ", cc2420_rssi() + 55);
  }
  printf("\n");
}

/*---------------------------------------------------------------------------*/
PROCESS(scanner_process, "RSSI Scanner");
AUTOSTART_PROCESSES(&scanner_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(scanner_process, ev, data)
{
  PROCESS_BEGIN();
  /* switch mac layer off, and turn radio on */
  NETSTACK_MAC.off(0);
  cc2420_on();

  while(1) {
    do_rssi();
    PROCESS_PAUSE();
  }

  PROCESS_END();
}


Code 2

#include "contiki.h"
#include "net/rime/rime.h"
#include "net/netstack.h"

#include "dev/leds.h"
#include "cc2420.h"
#include "cc2420_const.h"
#include "dev/spi.h"
#include <stdio.h>

/*---------------------------------------------------------------------------*/
/* This assumes that the CC2420 is always on and "stable" */
static void
set_frq(int c)
{
  int f;
  /* We can read even other channels with CC2420! */
  /* Fc = 2048 + FSCTRL  ;  Fc = 2405 + 5(k-11) MHz, k=11,12, ... , 26 */
  f = c + 352; /* Start from 2400 MHz to 2485 MHz, */

  /* Write the new channel value */
  CC2420_SPI_ENABLE();
  SPI_WRITE_FAST(CC2420_FSCTRL);
  SPI_WRITE_FAST((uint8_t)(f >> 8));
  SPI_WRITE_FAST((uint8_t)(f & 0xff));
  SPI_WAITFORTx_ENDED();
  SPI_WRITE(0);

  /* Send the strobe */
  SPI_WRITE(CC2420_SRXON);
  CC2420_SPI_DISABLE();
}
static void
do_rssi(void)
{
  int channel;
  printf("RSSI:");
  for(channel = 0; channel <= 85; ++channel) {
    set_frq(channel);
    printf("%d ", cc2420_rssi() + 55);
  }
  printf("\n");
}
/*---------------------------------------------------------------------------*/
PROCESS(scanner_process, "RSSI Scanner");
AUTOSTART_PROCESSES(&scanner_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(scanner_process, ev, data)
{
  PROCESS_BEGIN();
  /* switch mac layer off, and turn radio on */
  NETSTACK_MAC.off(0);
  cc2420_on();

  while(1) {
    do_rssi();
    PROCESS_PAUSE();
  }

  PROCESS_END();
}
/*---------

Code 3

#include "/home/YOURUSER/contiki-3.0/dev/cc2420/cc2420.h" // In order to recognize the variable cc2420_last_rssi
//Your code...
  // Declare the variables that you will use
  static signed char rss;
  static signed char rss_val;
  static signed char rss_offset;
  rss_val = cc2420_last_rssi;  // Get the RSSI from the last received packet
  rss_offset = -45; // Datasheet of cc2420 page 49 says you must decrease the value in -45
  rss = rss_val + rss_offset; // The RSSI correct value in dBm
  printf("RSSI of Last Received Packet = %d\n",rss);

Comments

Popular Posts