Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
//
//
//
//
//
//
//
//
//
//
//
//
//
//
->
->
->
->
and CE
-> 9
10
11
12
13
#define CE 9
// Array to hold Channel data
#define CHANNELS 64
int channel[CHANNELS];
// greyscale mapping
int line;
char grey[] = " .:-=+*aRW";
// nRF24L01P registers we
#define _NRF24_CONFIG
#define _NRF24_EN_AA
#define _NRF24_RF_CH
#define _NRF24_RF_SETUP
#define _NRF24_RPD
need
0x00
0x01
0x05
0x06
0x09
delayMicroseconds(130);
}
// switch nRF24L01p off
void powerDown(void)
{
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)&~0x02);
}
// enable RX
void enable(void)
{
PORTB |= _BV(1);
}
// disable RX
void disable(void)
{
PORTB &=~_BV(1);
}
// setup RX-Mode of nRF24L01p
void setRX(void)
{
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x01);
enable();
// this is slightly shorter than
// the recommended delay of 130 usec
// - but it works for me and speeds things up a little...
delayMicroseconds(100);
}
// scanning all channels in the 2.4GHz band
void scanChannels(void)
{
disable();
for( int j=0 ; j<200 ; j++)
{
for( int i=0 ; i<CHANNELS ; i++)
{
// select a new channel
setRegister(_NRF24_RF_CH,(128*i)/CHANNELS);
// switch on RX
setRX();
// wait enough for RX-things to settle
delayMicroseconds(40);
// this is actually the point where the RPD-flag
// is set, when CE goes low
disable();
// read out RPD flag; set to 1 if
// received power > -64dBm
if( getRegister(_NRF24_RPD)>0 ) channel[i]++;
}
}
}
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setBitOrder(MSBFIRST);
// Activate Chip Enable
pinMode(CE,OUTPUT);
disable();
// now start receiver
powerUp();
// switch off Shockburst
setRegister(_NRF24_EN_AA,0x0);
// make sure RF-section is set properly
// - just write default value...
setRegister(_NRF24_RF_SETUP,0x0F);
// reset line counter
line = 0;
}
void loop()
{
// do the scan
scanChannels();
// output the result
outputChannels();
// output WLAN-channel reference every 12th line
if( line++>12 )
{
printChannels();
line = 0;
}
}