Library to send and receive data using RF12B transceiver modules Big thanks to the tutorial at https://loee.jottit.com/rfm12b_and_avr_-_quick_start and madcowswe
Dependents: Measure_system Quadcopter_copy
Diff: RF12B.h
- Revision:
- 4:2a295db9ba1a
- Parent:
- 3:e72ad65868ab
- Child:
- 5:a92c3f6d1711
--- a/RF12B.h Thu Mar 10 13:14:48 2011 +0000 +++ b/RF12B.h Thu Mar 10 17:26:42 2011 +0000 @@ -2,38 +2,63 @@ #define _RF12B_H #include "mbed.h" +#include <queue> + +#define PACKET_LEN 16 + +enum rfmode_t{RX, TX}; class RF12B { public: + /* Constructor */ RF12B(PinName SDI, PinName SDO, PinName SCK, PinName NCS, PinName NIRQ); - /* Reads a byte of data from the RF module's buffer - This is a blocking call */ + /* Reads a byte of data from the receive buffer + Returns 0xFF if there is no data */ unsigned char read(); - /* Sends a byte of data to the RF module for transmission */ - void write(unsigned char * data, unsigned int length); - - /* Flushes all data from the RF module's buffer */ - void flush(); + /* Transmits a packet of data */ + void write(unsigned char * data, unsigned char length); + + /* Transmits a 1-byte packet of data */ + void write(unsigned char data); + + /* Returns true if data is available in the receive buffer*/ + bool available(); private: + /* Receive FIFO buffer */ + queue<unsigned char> fifo; + + /* SPI module */ SPI spi; + + /* Other digital pins */ DigitalOut NCS; - DigitalIn NIRQ; - bool trans; - bool initialized; + InterruptIn NIRQ; + DigitalIn NIRQ_in; - unsigned int writeCmd(unsigned int cmd); - void send(unsigned char data); /* Initialises the RF12B module */ void init(); + + /* Write a command to the RF Module */ + unsigned int writeCmd(unsigned int cmd); + + /* Sends a byte of data across RF */ + void send(unsigned char data); + /* Switch module between receive and transmit modes */ - void mode(bool trans); + void changeMode(rfmode_t mode); + + /* Interrupt routine for data reception */ + void rxISR(); + + /* Tell the RF Module this packet is received and wait for the next */ + void resetRX(); }; #endif /* _RF12B_H */ \ No newline at end of file