\ main-3.fs \ receive rfm12 OOK telegrams (44 Bits) \ use int0-isr to receive the bits, \ use timer1-isr to measure pulse lengths \ rfm12 power is on PORTA.7! include part1.fs decimal \ --- TX2,3,4 sensor reading ---------- \ data telegramms are send and received \ in chunks of 44 Bits &44 constant bits/telegram variable bit# \ with timer1 driven by f_cpu/64 \ (11059200/64=172800Hz) a pulse \ indicating a one (~ 600 \mu seconds) \ results in counts ~ 100. A zero pulse \ (~1300 \mu seconds) results in counts \ ~ 225. \ Measurements yield ~ 150 and ~ 300 \ counts. So counts below 200 are taken \ as logical 1 &200 constant bit=1 \ indicate a full frame has been \ received, triggers processing of \ the received frame variable fQueue include rfm12_timer1.fs &44 constant RXsize \ receive buffer, really too large variable RXbuf RXsize cells allot \ nibble shift register variable RXtmp include rfm12_int1.fs : .data hex bits/telegram 4 / 0 do RXbuf i + c@ 2 u0.r space loop ; include ewlib/format.fs 11 constant frame.size : .D ( addr -- ) hex dup >r \ --- raw dump of data --- frame.size 0 do dup i + c@ 2 u0.r space loop cr drop \ --- address --- r@ 1 + c@ 12 lshift r@ 2 + c@ 8 lshift + r@ 3 + c@ 4 lshift + r@ 4 + c@ + $fffe and \ addr ." addr:" space 4 u0.r cr \ --- value and unit --- r@ 5 + c@ \ temperature? r@ 2 + c@ 0= if 5 - then 100 * r@ 6 + c@ 10 * + r@ 7 + c@ + \ value decimal r@ 2 + c@ 0= if ." T C:" else ." rF %:" then space 1 +.f cr \ --- checksum --- r@ 0 frame.size 1- 0 do over i + c@ + loop swap drop $000f and \ crc hex dup ." crc:" space 4 u0.r space r@ frame.size 1- + c@ dup space 4 u0.r space = if ." ok." else ." invalid" then cr r> drop ; : init3 led_0 high led_0 pin_output led_1 high led_1 pin_output led_2 high led_2 pin_output led_3 high led_3 pin_output -jtag rfm12.power.on &1000 ms +spi +rfm12 rfm12.init-ook _data pin_input RXbuf RXsize cells erase 0 fQueue ! +timer1 +int1 ; : run3 init3 w.status cr begin fQueue @ 0 > if .data cr RXbuf .D 0 fQueue ! then key? until key drop rfm12.power.off ;