Add more wrapper functions to hide more of the raw register accesses
This commit is contained in:
parent
cb92166dcd
commit
effe217111
|
@ -34,11 +34,10 @@ void setup() {
|
|||
|
||||
volatile uint8_t gotrx;
|
||||
volatile uint8_t txok;
|
||||
volatile uint8_t last_interrupt;
|
||||
|
||||
void interrupt_routine() {
|
||||
// read and clear from the radio
|
||||
last_interrupt = mrf.read_short(MRF_INTSTAT);
|
||||
byte last_interrupt = mrf.read_short(MRF_INTSTAT);
|
||||
if (last_interrupt & MRF_I_RXIF) {
|
||||
gotrx = 1;
|
||||
}
|
||||
|
@ -72,7 +71,7 @@ void loop() {
|
|||
if (gotrx) {
|
||||
gotrx = 0;
|
||||
noInterrupts();
|
||||
mrf.write_short(MRF_BBREG1, 0x04); // RXDECINV - disable receiver
|
||||
mrf.rx_disable();
|
||||
|
||||
byte frame_length = mrf.read_long(0x300); // read start of rxfifo
|
||||
Serial.print("received a packet ");Serial.print(frame_length, DEC);Serial.println(" bytes long");
|
||||
|
@ -87,7 +86,7 @@ void loop() {
|
|||
Serial.print(lqi, HEX);
|
||||
Serial.println(rssi, HEX);
|
||||
|
||||
mrf.write_short(MRF_BBREG1, 0x00); // RXDECINV - enable receiver
|
||||
mrf.rx_enable();
|
||||
interrupts();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Example code for using a microchip mrf24j40 module in receive mode only
|
||||
* Example code for using a microchip mrf24j40 module to receive only
|
||||
* packets using plain 802.15.4
|
||||
* Requirements: 3 pins for spi, 3 pins for reset, chip select and interrupt
|
||||
* notifications
|
||||
|
@ -21,15 +21,15 @@ void setup() {
|
|||
mrf.set_pan(0xcafe);
|
||||
// This is _our_ address
|
||||
mrf.address16_write(0x6001);
|
||||
mrf.set_channel(12);
|
||||
|
||||
// uncomment if you want to receive any packet on this channel
|
||||
// mrf.set_promiscuous(true);
|
||||
|
||||
attachInterrupt(0, interrupt_routine, CHANGE);
|
||||
interrupts();
|
||||
}
|
||||
|
||||
volatile byte gotrx;
|
||||
volatile uint8_t gotrx;
|
||||
|
||||
void interrupt_routine() {
|
||||
// read and clear from the radio
|
||||
|
@ -41,25 +41,31 @@ void interrupt_routine() {
|
|||
|
||||
void loop() {
|
||||
int tmp;
|
||||
interrupts();
|
||||
if (gotrx) {
|
||||
gotrx = 0;
|
||||
noInterrupts();
|
||||
mrf.write_short(MRF_BBREG1, 0x04); // RXDECINV - disable receiver
|
||||
mrf.rx_disable();
|
||||
|
||||
// read start of rxfifo
|
||||
byte frame_length = mrf.read_long(0x300);
|
||||
Serial.print("received a packet ");
|
||||
Serial.print(frame_length, DEC);
|
||||
Serial.println(" bytes long");
|
||||
|
||||
byte frame_length = mrf.read_long(0x300); // read start of rxfifo
|
||||
Serial.print("received a packet ");Serial.print(frame_length, DEC);Serial.println(" bytes long");
|
||||
Serial.println("Packet data:");
|
||||
for (int i = 1; i <= frame_length; i++) {
|
||||
tmp = mrf.read_long(0x300 + i);
|
||||
Serial.print(tmp, HEX);
|
||||
}
|
||||
|
||||
Serial.print("\r\nLQI/RSSI=");
|
||||
byte lqi = mrf.read_long(0x300 + frame_length + 1);
|
||||
byte rssi = mrf.read_long(0x300 + frame_length + 2);
|
||||
Serial.print(lqi, HEX);
|
||||
Serial.println(rssi, HEX);
|
||||
|
||||
mrf.write_short(MRF_BBREG1, 0x00); // RXDECINV - enable receiver
|
||||
mrf.rx_enable();
|
||||
interrupts();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void interrupt_routine() {
|
|||
byte last_interrupt = mrf.read_short(MRF_INTSTAT);
|
||||
// we don't care about the rx acks, but we need them to be flushed so it can keep receiving
|
||||
if (last_interrupt & MRF_I_RXIF) {
|
||||
mrf.write_short(MRF_RXFLUSH, 0x01);
|
||||
mrf.rx_flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
mrf24j.cpp
12
mrf24j.cpp
|
@ -175,3 +175,15 @@ void Mrf24j::set_promiscuous(boolean enabled) {
|
|||
write_short(MRF_RXMCR, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
void Mrf24j::rx_flush(void) {
|
||||
write_short(MRF_RXFLUSH, 0x01);
|
||||
}
|
||||
|
||||
void Mrf24j::rx_disable(void) {
|
||||
write_short(MRF_BBREG1, 0x04); // RXDECINV - disable receiver
|
||||
}
|
||||
|
||||
void Mrf24j::rx_enable(void) {
|
||||
write_short(MRF_BBREG1, 0x00); // RXDECINV - enable receiver
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue