#include <SPI.h>
#include <RF22.h>
void setup()
{
Serial.begin(9600);
Serial.println("RF22 init failed");
}
void
test_read_write()
{
uint8_t val;
rf22.
spiWrite(RF22_REG_42_CHECK_HEADER0, 10);
val = rf22.
spiRead(RF22_REG_42_CHECK_HEADER0);
Serial.println(val, DEC);
rf22.
spiWrite(RF22_REG_42_CHECK_HEADER0, 5);
val = rf22.
spiRead(RF22_REG_42_CHECK_HEADER0);
Serial.println(val, DEC);
Serial.println("-----");
}
void
test_adc()
{
uint8_t val = rf22.
adcRead(RF22_ADCSEL_GND);
Serial.println(val, HEX);
}
void test_temp()
{
Serial.println(val, HEX);
}
void
test_burst_read()
{
uint8_t buf[127];
uint8_t i;
for (i = 0; i < 127; i++)
{
Serial.print(i, HEX);
Serial.print(": ");
Serial.println(buf[i], HEX);
}
}
void test_burst_write()
{
uint8_t buf[] = "Hello";
}
void
test_wut()
{
Serial.println("WUT Start");
rf22.
spiWrite(RF22_REG_07_OPERATING_MODE1, RF22_ENWT);
while (1)
{
uint8_t val = rf22.
spiRead(RF22_REG_04_INTERRUPT_STATUS2);
if (val & RF22_IWUT)
break;
}
rf22.
spiWrite(RF22_REG_07_OPERATING_MODE1, 0);
Serial.println("WUT Interrupt bit detected OK");
}
void
test_set_frequency()
{
Serial.println("setFHStepSize 1 Fail");
Serial.println("setFHChannel 1 Fail");
Serial.println("setFrequency 1 Fail");
Serial.println("setFrequency 2 Fail");
Serial.println("setFrequency 3 Fail");
Serial.println("setFrequency 4 Fail");
Serial.println("-------------");
}
void
test_rssi()
{
float f = 430.0;
while (f < 435.0)
{
delayMicroseconds(200);
Serial.print(f);
Serial.print(": ");
Serial.println(rssi, DEC);
f += 1.0;
}
Serial.println("-------------");
}
void test_tx_pn9()
{
delay(1);
delay(1);
delay(500);
delay(10);
Serial.println("-------------");
delay(500);
}
void test_analog_gpio()
{
rf22.
spiWrite(RF22_REG_0C_GPIO_CONFIGURATION1, 0x0c);
rf22.
spiWrite(RF22_REG_0D_GPIO_CONFIGURATION2, 0x0d);
rf22.
spiWrite(RF22_REG_50_ANALOG_TEST_BUS_SELECT, 15);
while (1);
}
void test_modem_config()
{
Serial.println("setModemConfig 1 failed");
Serial.println("setModemConfig 2 failed");
Serial.println("setModemConfig 3 failed");
Serial.println("setModemConfig 3 failed");
Serial.println("setModemConfig 4 failed");
Serial.println("-------------");
}
void test_tx()
{
Serial.println("setFrequency failed");
Serial.println("setModemConfig failed");
uint8_t data[] = "hello";
rf22.
send(data,
sizeof(data));
Serial.println("-------------");
}
void test_rx()
{
Serial.println("setFrequency failed");
Serial.println("setModemConfig failed");
while (1)
{
uint8_t buf[RF22_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf22.
recv(buf, &len))
Serial.println("recv 1 failed");
if (rf22.
recv(buf, &len))
{
Serial.print("got one in user: ");
Serial.println((char*)buf);
}
else
{
Serial.print("recv 2 failed");
}
}
}
void loop()
{
test_tx_pn9();
delay(1000);
}