Karl Zweimüller
/
eth_comfort_test
Programm for decoding radio-signals sent by a ETH-Window-Shutter-Contact, received with a RFM12B-module
Revision 1:fc72e0bdb693, committed 2011-04-07
- Comitter:
- charly
- Date:
- Thu Apr 07 19:54:09 2011 +0000
- Parent:
- 0:96794c9fc5a3
- Commit message:
- Reorganized and created classes for RFM12B and ETH-Comfort
Changed in this revision
--- a/eth_comfort.cpp Wed Mar 02 20:46:57 2011 +0000 +++ b/eth_comfort.cpp Thu Apr 07 19:54:09 2011 +0000 @@ -5,7 +5,7 @@ Modulation FSK Hub +/- 15kHz Datenrate 10kbit Manchester - + das Protokoll ist Machester codiert 0x7e zz ll aa aa aa cmd crc crc @@ -18,15 +18,15 @@ die Reihenfolge der Bits im Byte ist verdreht. */ - - -// WED 6.9.2009 -// extended and adapeted to mbed by Karl Zweimueller 1/2011 +/*! + * \file eth_comfort.cpp + * \brief Read the messages from the ETH-Radio-Shutter + * \author Karl Zweimüller based on code from WED 6.9.2009 + */ #include "eth_comfort.h" - /* orig AVR-values #define BIT_MAX 0x90 #define BIT_MIN 0x10 @@ -40,23 +40,27 @@ #define LEN_2T 200 // time-value to differentiate one or two bit length -volatile uint16_t b; - -volatile uint8_t transmit,bit_cnt; -volatile uint16_t buffer_cnt; - - -volatile unsigned char old ; -volatile uint8_t rbyte; - -volatile uint8_t buf[1024]; -volatile uint8_t pack_ok,startbit; -volatile uint8_t decode,bcnt,lastbit; -volatile uint8_t state; - // Timer for bit-length-measurement Timer BitTime; + +eth_comfort::eth_comfort(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata, PinName rxled) { + + rfm12b_spi = new rfm12b(mosi,miso,sclk,nsel,rxdata); + + // the ReceiveLED + rxLED = new DigitalOut(rxled); + + // init the eth_receiver + init(); + + // Interrupt on every bit-change + rfm12b_spi->attachISR(this, ð_comfort::ISR); + + // Init the RFM12B + rfm12b_spi->RFM_init(); + +}; //------------------------------------------------------------------------- // calcCRC16r() //------------------------------------------------------------------------- @@ -67,29 +71,57 @@ * @param mask crc polynom * @return crc value */ -uint16_t calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask) // reverser crc!!!!!! -{ -uint8_t i; - for(i=0;i<8;i++) - { - if((crc ^ c) & 1) { crc=(crc>>1)^mask; } - else crc>>=1; - c>>=1; - }; - return(crc); +uint16_t eth_comfort::calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask) { // reverse crc!!!!!! + uint8_t i; + for (i=0;i<8;i++) { + if ((crc ^ c) & 1) { + crc=(crc>>1)^mask; + } else crc>>=1; + c>>=1; + }; + return(crc); } // initialize eth_receiver -void eth_init() -{ - // start timer for bit-length-measurement - BitTime.start(); +void eth_comfort::init() { + + rbyte=0; + bit_cnt=0; + buffer_cnt=0; + decode=0; + pack_ok=0; + // start timer for bit-length-measurement + BitTime.start(); + message_received = false; + // init the buffer + last_message.cnt = 0; + last_message.len = 0; + last_message.adr = 0; + last_message.cmd = 0; + last_message.data = 0; + last_message.xdata = 0; + last_message.crc = 0; + + new_message = last_message; } -// -// -// + +// is a new message readable +bool eth_comfort::readable() { + return(message_received); +} + +// read a eth-messsage +eth_message eth_comfort::getMessage() { + if (readable()) { + last_message = new_message; + message_received = false; + return(new_message); + } else + // we should return nothing here! + return(last_message); +} /** ISR Interrupt routine for received data * triggers on every pin change high/low and low/high @@ -97,106 +129,163 @@ * as the eth doesn't send a good signal, which the rfm12 could decode for himself * didn't test for myself - just got the code from someone else and ported to mbed! */ -void ISR() // pin change on rxin ->interrupt -{ - //led2=!led2; - b=BitTime.read_us(); // time since last change - BitTime.reset(); +void eth_comfort::ISR() { // pin change on rxin ->interrupt + //led2=!led2; + b=BitTime.read_us(); // time since last change + BitTime.reset(); + + if ((b>BIT_MAX)||(b<BIT_MIN)) { // is bit time in range? + state=0; + } else { + + + if (state==0) { // wait for first bitchange 2T + if (b>LEN_2T)state=1; + //if((rxin)!=0)state=0; // level should be low + } else if (state<=10) { // wait for 5 fullbit without bitchange 10 shortbits + if (b<LEN_2T)state++; + else state=1; // bitchange found back to state 1 + } else if (state==11) { // now expecting bitchange (last bit in 7e is 0) + if (b<LEN_2T) { + state=0; // no bitchange -> back to search + }; + state=20; // now we found 7e sync finished + rbyte=0x7e; // set shift value to 0 + bit_cnt=8; // clear bitcounter + buffer_cnt=0; // clear buffercounter + bcnt=0; + lastbit=0; - if((b>BIT_MAX)||(b<BIT_MIN)){ // is bit time in range? - state=0; - } - else{ + } else if (state==20) { + if (b>LEN_2T) { // check for bitchange + if (lastbit!=0) { + rbyte=(rbyte>>1); // last bit was 1 new is 0 + bcnt=0; + lastbit=0; + } else { + rbyte=(rbyte>>1)|0x80; // last bit was 0 new is 1 + bcnt++; + lastbit=1; + } + state=20; // fullbit compleate + bit_cnt++; // increase bit counter + } else { + state=21; // bit is halfbit, wait for next halfbit + }; + } else if (state==21) { // no bitchange + if (b<LEN_2T) { // next bit must be a halfbit + if (lastbit==0) { + rbyte=(rbyte>>1); // last bit was 0 new is 0 + lastbit=0; + bcnt=0; + } else { + rbyte=(rbyte>>1)|0x80; // last bit was 1 new is 1 + lastbit=1; + bcnt++; + } + state=20; + bit_cnt++; + } else { + state=0; // bit is no halfbit -> Manchester violation + // state=20; + }; + } else if (state==22) { // after 5 bit 1 skip one bit 0 + if (b>LEN_2T) { // check for bitchange (next bit 0) + lastbit=0; + state=20; + } else { + + lastbit=1; + //state=11; + state=21; + } + bcnt=0; - if(state==0){ // wait for first bitchange 2T - if(b>LEN_2T)state=1; - //if((rxin)!=0)state=0; // level should be low - } - else if(state<=10){ // wait for 5 fullbit without bitchange 10 shortbits - if(b<LEN_2T)state++; - else state=1; // bitchange found back to state 1 - } - else if(state==11){ // now expecting bitchange (last bit in 7e is 0) - if(b<LEN_2T){ - state=0; // no bitchange -> back to search - }; - state=20; // now we found 7e sync finished - rbyte=0x7e; // set shift value to 0 - bit_cnt=8; // clear bitcounter - buffer_cnt=0; // clear buffercounter - bcnt=0; - lastbit=0; + } + if (bcnt==5)state=22; + + if (bit_cnt>7) { // wait for 8 bits + buf[buffer_cnt]=rbyte; // save value into buffer + if (buffer_cnt<1020) { + buffer_cnt++; + }; + pack_ok=1; // set receiveflag + bit_cnt=0; // clear bitcounter + *rxLED = ! *rxLED; //show received byte + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + //here we received another byte - } - else if(state==20){ - if(b>LEN_2T){ // check for bitchange - if(lastbit!=0){ - rbyte=(rbyte>>1); // last bit was 1 new is 0 - bcnt=0; - lastbit=0; - } - else { - rbyte=(rbyte>>1)|0x80; // last bit was 0 new is 1 - bcnt++; - lastbit=1; - } - state=20; // fullbit compleate - bit_cnt++; // increase bit counter - } - else{ - state=21; // bit is halfbit, wait for next halfbit - }; - } - else if(state==21){ // no bitchange - if(b<LEN_2T){ // next bit must be a halfbit - if(lastbit==0){ - rbyte=(rbyte>>1); // last bit was 0 new is 0 - lastbit=0; - bcnt=0; - } - else { - rbyte=(rbyte>>1)|0x80; // last bit was 1 new is 1 - lastbit=1; - bcnt++; - } - state=20; - bit_cnt++; - } - else{ - state=0; // bit is no halfbit -> Manchester violation - // state=20; - }; - }else if(state==22){ // after 5 bit 1 skip one bit 0 - if(b>LEN_2T){ // check for bitchange (next bit 0) - lastbit=0; - state=20; - } - else{ + // we have to check if we are ready with the message + if (buffer_cnt>8) { + if (buf[2]==0x10) blocklength=10; + else if (buf[2]==0x20) blocklength=9; + else blocklength=99; + j=0; + crc_ok = false; + for (i=0;i<=buffer_cnt;i++) { + //pc.printf("%02X ",buf[i]); + j++; + if (j==blocklength) { + //check crc + if (blocklength==9) { + crc=0xbdb7; + for (k=0;k<7;k++) { // crc over first 7 byte + crc=calcCRC16r(buf[k],crc,0x8408); + } + //swap the two crc-bytes + swapped = ((crc >> 8) & 0xff) | ((crc << 8) & 0xff00); + //pc.printf("CRC: %04X ",swapped); + if (((buf[7]<<8) | buf[8]) == swapped) crc_ok = true; + else crc_ok = false; + //pc.printf("%s", (crc_ok==true) ? "OK" : "Not OK"); + if (crc_ok) { + /* + pc.printf("\n\rCounter: %02X\n\r",buf[1]); + pc.printf( " Dev-ID: %02X %02X %02X\n\r",buf[3],buf[4],buf[5]); + //pc.printf( "Battery: %s\n\r", (buf[6]&0x80 != 0x00) ? "WEAK" : "GOOD"); + pc.printf( "Window : %s\n\r\n\r", (buf[6]&0x01 != 0x00) ? "OPEN" : "CLOSE"); + lcd.cls(); + lcd.printf("#:%02X ID: %02X%02X%02X\n",buf[1],buf[3],buf[4],buf[5]); + lcd.printf("Window : %s\n", (buf[6]&0x01 != 0x00) ? "OPEN" : "CLOSE"); + */ - lastbit=1; - //state=11; - state=21; - } - bcnt=0; + // insert buf into message + new_message.cnt = buf[1]; + new_message.len = buf[2]; + new_message.adr = buf[3]<<16 | buf[4]<<8 | buf[5]; + new_message.cmd = buf[6]; + new_message.data = buf[7]; + new_message.xdata = 0; + new_message.crc = swapped; + + //is the new message different from the old message? + if (new_message.cnt != last_message.cnt) { + last_message = new_message; + message_received = true; + } + + } //crc_ok + } //block_length = 9 + } //j==blocklength + } //for - } - if(bcnt==5)state=22; + //start receive from beginning + buffer_cnt=0; + bit_cnt=0; + startbit=0; + state=0; + //pc.printf("\n\r-----------------------------\n\r"); + //clear the buffer + for (i=0;i<1023;i++)buf[i]=0; + *rxLED = 0; //turn off receive led + } //buffer_cnt >8 + ////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + } + } - if(bit_cnt>7){ // wait for 8 bits - buf[buffer_cnt]=rbyte; // save value into buffer - if(buffer_cnt<1020){ - buffer_cnt++; - }; - pack_ok=1; // set receiveflag - bit_cnt=0; // clear bitcounter - led3= !led3; //show received byte - - // - }; - }; - }
--- a/eth_comfort.h Wed Mar 02 20:46:57 2011 +0000 +++ b/eth_comfort.h Thu Apr 07 19:54:09 2011 +0000 @@ -1,45 +1,98 @@ #ifndef ETH_COMFORT_H #define ETH_COMFORT_H +/*! + * \file eth_comfort.h + * \brief Read the messages from the ETH-Radio-Shutter + * \author Karl Zweimüller + */ + + #include "mbed.h" +#include "rfm12b.h" + +// a message from the eth-Device +struct eth_message { + uint8_t cnt; //message-counter + uint8_t len; //message-length + uint32_t adr; // unique address of device + uint8_t cmd; // the command + uint8_t data; // optional data + uint8_t xdata; // optional extra data + uint16_t crc; // crc fro the message +}; + +/** + * Class for the ETH-Window shutter by ELV(R) + * Uses the rfm12B to receive the signals sent by the radio-shutter + * + */ +class eth_comfort { + +public: + + /** + * Constructor. + * + * @param mosi SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p5 or p11 + * @param miso SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p6 or p12 + * @param sclk SPI-Interface. One of the 2 PSI-Interfaces of mbed. Pin p7 or p13 + * @param nsel Chip-Select. A Digial Output of mbed + * @param rxdata Data-Pin for received data. A DigitalIn of mbed + * @param rxled LED1 - LED4 for showing received bytes + */ + eth_comfort(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata, PinName rxled); + + +// initialize eth_comfort-receiver + void init(); + +// is a new message readable - non blocking + bool readable(); + +// read a eth-messsage - non blocking, shows the old message if no new is available + eth_message getMessage(); -extern volatile uint8_t transmit,start,phase,bit_cnt,data; -extern volatile uint16_t buffer_cnt; - - -extern volatile unsigned char old ; +private: -extern volatile uint8_t rbyte; - -extern volatile uint8_t buf[1024]; -extern volatile uint8_t pack_ok,startbit; -extern volatile uint8_t decode,bcnt,lastbit; -extern volatile uint8_t state; +// Interrupt Routine + void ISR(); -struct eth_message{ - uint8_t cnt; - uint8_t len; - uint32_t adr; - uint8_t cmd; - uint8_t data; - uint8_t xdata; - uint16_t crc; -}; +// the last received message + eth_message last_message; -// led3 shows received bits -extern DigitalOut led3; +// new meeesage + eth_message new_message; + +// is a new message in the buffer? + bool message_received; // calcualte the crc for eth -uint16_t calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask); + uint16_t calcCRC16r( uint16_t c,uint16_t crc, uint16_t mask); + + volatile uint8_t bit_cnt; + volatile uint16_t buffer_cnt; + + volatile uint8_t rbyte; -// initialize eth_comfort-receiver -void eth_init(); + volatile uint8_t buf[1024]; + volatile uint8_t pack_ok,startbit; + volatile uint8_t decode,bcnt,lastbit; + volatile uint8_t state; + volatile uint16_t b; + volatile uint8_t blocklength; + int i,j,k; + bool crc_ok; + uint16_t crc, swapped; -// interupt-routine for received data -void ISR(); + rfm12b *rfm12b_spi; + + DigitalOut *rxLED; + +}; #endif
--- a/main.cpp Wed Mar 02 20:46:57 2011 +0000 +++ b/main.cpp Thu Apr 07 19:54:09 2011 +0000 @@ -2,141 +2,63 @@ #include "TextLCD.h" -TextLCD lcd(p30, p29, p28, p27, p26, p25, TextLCD::LCD16x2); // rs, e, d0-d3 - #include "eth_comfort.h" #include "rfm.h" #include "rfm12b.h" -rfm12b rfm12b_spi(p11, p12, p13, p14, p18); // mosi, miso, sclk, cs, rxdata +/*! + * \file main.cpp + * \brief Show the messages from ETH-Radio-Shutters on serial port and lcd + * \author Karl Zweimüller + */ +TextLCD lcd(p30, p29, p28, p27, p26, p25, TextLCD::LCD16x2); // rs, e, d0-d3 + +eth_comfort eth_comf(p11, p12, p13, p14, p18, LED4); // mosi, miso, sclk, cs, rxdata, rxled Serial pc(USBTX, USBRX); // tx, rx // mbed LEDs +/* DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); - - - -//--------------------------------------------------------------------- - -void init(void) -{ - - - rbyte=0; - bit_cnt=0; - buffer_cnt=0; - - decode=0; - - pack_ok=0; // this will be set by ISR, when byte was received - - - // init the eth_receiver - eth_init(); - - // Interrupt on every bit-change - rfm12b_spi.attachISR(&ISR); - - // Init the RFM12B - rfm12b_spi.RFM_init(); - -} +*/ //--------------------------------------------------------------------- // //--------------------------------------------------------------------- -int main() -{ -uint8_t blocklength=0; -unsigned int i,j=0,k; -unsigned long timeout=0; -unsigned long tick=0; -uint16_t crc, swapped; -bool crc_ok = false; +int main() { + + eth_message message; - pc.baud(115200); - - pc.printf("\n\rConnected to mbed\n\r"); - lcd.printf("Hello!\n"); + pc.baud(115200); - init(); - - // state =start - startbit=0; - do{ + pc.printf("\n\rConnected to mbed\n\r"); + lcd.printf("Hello!\n"); - if (pack_ok==1){ - timeout=0; - pack_ok=0; - j=0; - }; - if(timeout<10000){ - timeout++; - } - else if(timeout==10000){ - if(buffer_cnt>8){ - if (buf[2]==0x10) blocklength=10; - else if(buf[2]==0x20) blocklength=9; - else blocklength=99; - j=0; - crc_ok = false; - for(i=0;i<=buffer_cnt;i++){ - pc.printf("%02X ",buf[i]); - j++; - if(j==blocklength){ - //check crc - if(blocklength==9){ - crc=0xbdb7; - for(k=0;k<7;k++){ // crc over first 7 byte - crc=calcCRC16r(buf[k],crc,0x8408); - } - //swap the two crc-bytes - swapped = ((crc >> 8) & 0xff) | ((crc << 8) & 0xff00); - pc.printf("CRC: %04X ",swapped); - if (((buf[7]<<8) | buf[8]) == swapped) crc_ok = true; - else crc_ok = false; - pc.printf("%s", (crc_ok==true) ? "OK" : "Not OK"); - if (crc_ok) { - pc.printf("\n\rCounter: %02X\n\r",buf[1]); - pc.printf( " Dev-ID: %02X %02X %02X\n\r",buf[3],buf[4],buf[5]); - //pc.printf( "Battery: %s\n\r", (buf[6]&0x80 != 0x00) ? "WEAK" : "GOOD"); - pc.printf( "Window : %s\n\r\n\r", (buf[6]&0x01 != 0x00) ? "OPEN" : "CLOSE"); - lcd.cls(); - lcd.printf("#:%02X ID: %02X%02X%02X\n",buf[1],buf[3],buf[4],buf[5]); - lcd.printf("Window : %s\n", (buf[6]&0x01 != 0x00) ? "OPEN" : "CLOSE"); - } - } - pc.printf("\n\r"); - } - } - - - //start receive from beginning - buffer_cnt=0; - bit_cnt=0; - timeout++; - startbit=0; - state=0; + do { + // anything new? + if (eth_comf.readable()) { + // read the new message and display + message = eth_comf.getMessage(); + pc.printf("\n\rCounter: %02X\n\r",message.cnt); + pc.printf( " Dev-ID: %06X\n\r",message.adr); + pc.printf( " cmd: %0X\n\r",message.cmd); + //pc.printf( "cmd&0x80: %0X\n\r",message.cmd&0x80); + // why doesn't work the following?????????????? + //pc.printf( "Battery: "); + //if (message.cmd&0x80 == 0x00) pc.printf("GOOD\n\r"); else pc.printf("WEAK\n\r"); - pc.printf("\n\r-----------------------------\n\r"); - for(i=0;i<1023;i++)buf[i]=0; - }; - timeout = 0; - }; - tick++; - //delay_ms(100); - if(tick>=2000000){ - tick=0; - led1= !led1; - led3=0; // reset receive-led - }; -}while(1==1); + pc.printf( "Window : %s\n\r\n\r", (message.cmd&0x01 != 0x00) ? "OPEN" : "CLOSE"); + lcd.cls(); + lcd.printf("#:%02X ID: %06X\n",message.cnt,message.adr); + lcd.printf("Window : %s\n", (message.cmd&0x01 != 0x00) ? "OPEN" : "CLOSE"); + pc.printf("\n\r"); + } + } while (1==1); }
--- a/rfm12b.cpp Wed Mar 02 20:46:57 2011 +0000 +++ b/rfm12b.cpp Thu Apr 07 19:54:09 2011 +0000 @@ -2,39 +2,45 @@ #include "rfm12b.h" #include "rfm.h" +/*! + * \file rfm12b.cpp + * \brief class for rfm2b in rawmode - only receive part implemented + * \author Karl Zweimüller based on code from WED 6.9.2009 + */ + + /** Class rfm12b for RFM12B transceiver module http://www.hoperf.com/rf_fsk/rfm12b.htm */ /** rfm12b object */ -rfm12b::rfm12b(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata){ - - rfm12b_spi = new SPI(mosi, miso, sclk); // mosi, miso, sclk - cs = new DigitalOut(nsel); // nsel for chipselect - m_pinRXData = new InterruptIn(rxdata); // rxData- generates interrupts +rfm12b::rfm12b(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata) { - init_spi(); // init the spi-device + rfm12b_spi = new SPI(mosi, miso, sclk); // mosi, miso, sclk + cs = new DigitalOut(nsel); // nsel for chipselect + m_pinRXData = new InterruptIn(rxdata); // rxData- generates interrupts + + init_spi(); // init the spi-device } - /** init the spi-communication - */ -void rfm12b::init_spi(){ +/** init the spi-communication +*/ +void rfm12b::init_spi() { // Setup the spi for 16 bit data : 1RW-bit 7 adressbit, 8 databit // second edge capture, with a 5MHz clock rate rfm12b_spi->format(16,0); rfm12b_spi->frequency(5000000); } - + /////////////////////////////////////////////////////////////////////////////// // // Initialise RF module // This are parameters for ETH Comfort by ELV /////////////////////////////////////////////////////////////////////////////// -void rfm12b::RFM_init(void) -{ +void rfm12b::RFM_init(void) { - // 0. Init the SPI backend + // 0. Init the SPI backend //RFM_TESTPIN_INIT; //RFM_READ_STATUS(); @@ -45,7 +51,7 @@ //RFM_CONFIG_EF | RFM_CONFIG_BAND_868 | RFM_CONFIG_X_11_0pf - ); + ); // 2. Power Management Command //RFM_SPI_16( @@ -56,10 +62,10 @@ RFM_SPI_16( RFM_FREQUENCY | RFM_FREQ_868Band(868.30) - ); + ); // 4. Data Rate Command - RFM_SPI_16(RFM_DATA_RATE_9600); + RFM_SPI_16(RFM_DATA_RATE_9600); // 5. Receiver Control Command RFM_SPI_16( @@ -69,7 +75,7 @@ RFM_RX_CONTROL_BW_134 | RFM_RX_CONTROL_GAIN_0 | RFM_RX_CONTROL_RSSI_73 - ); + ); // 6. Data Filter Command RFM_SPI_16( @@ -77,13 +83,13 @@ //RFM_DATA_FILTER_ML | //RFM_DATA_FILTER_DQD(3) RFM_DATA_FILTER_ANALOG - ); + ); // 7. FIFO and Reset Mode Command RFM_SPI_16( RFM_FIFO_IT(8) | RFM_FIFO_DR - ); + ); // 8. Receiver FIFO Read @@ -94,13 +100,13 @@ RFM_AFC_EN | RFM_AFC_OE | RFM_AFC_FI - ); + ); // 10. TX Configuration Control Command RFM_SPI_16( RFM_TX_CONTROL_MOD_30 | RFM_TX_CONTROL_POW_0 - ); + ); // 11. Transmitter Register Write Command @@ -116,18 +122,18 @@ // ); // 15. Status Read Command - //RFM_SPI_16(RFM_TX_ON()); - RFM_SPI_16(RFM_RX_ON()); + //RFM_SPI_16(RFM_TX_ON()); + RFM_SPI_16(RFM_RX_ON()); } /////////////////////////////////////////////////////////////////////////////// - + /** write and read 16 bit to device */ -uint16_t rfm12b::rfm_spi16(uint16_t outval){ +uint16_t rfm12b::rfm_spi16(uint16_t outval) { uint16_t readval; // Select the device by seting chip select low @@ -138,7 +144,7 @@ // Deselect the device cs->write(1); wait_ms(1); // wait before going on - return(readval); + return(readval); }
--- a/rfm12b.h Wed Mar 02 20:46:57 2011 +0000 +++ b/rfm12b.h Thu Apr 07 19:54:09 2011 +0000 @@ -3,14 +3,19 @@ #include <mbed.h> +/*! + * \file rfm12b.h + * \brief class for rfm2b in rawmode - only receive part implemented + * \author Karl Zweimüller based on code from WED 6.9.2009 + */ + typedef unsigned char Byte; // used to be uint8_t : something a byte wide, whatever .... /** This Class handles a rfm12b transceiver * see http://www.hoperf.com/rf_fsk/rfm12b.htm - * + * */ -class rfm12b -{ +class rfm12b { public: /** Create a rfm12b object * @@ -21,15 +26,15 @@ * @param rxdata Data-Pin for received data. A DigitalIn of mbed */ rfm12b(PinName mosi, PinName miso, PinName sclk, PinName nsel, PinName rxdata); - + /** init the spi-interface */ void init_spi(); - + /** initialize the device */ void RFM_init(void); - + /** write and read 16 bit */ uint16_t rfm_spi16(uint16_t outval); @@ -45,14 +50,29 @@ m_pinRXData->rise(fptr); } + template<typename T> + /** attach an object member function to be called when the data-pin changes from 0->1 and from 1->0 + * + * @param tptr pointer to object + * @param mprt pointer ro member function + * + */ + void attachISR(T* tptr, void (T::*mptr)(void)) { + if ((mptr != NULL) && (tptr != NULL)) { + m_pinRXData->fall(tptr, mptr); + m_pinRXData->rise(tptr, mptr); + } + } + + private: - + DigitalOut *cs; //chipselect InterruptIn *m_pinRXData; //rx data pin SPI *rfm12b_spi; //spi-interface - + };