Been debugging some RFM12B code again today. Reception is not as simple a matter as it could be because the documentation doesn’t really explain how it is supposed to work. I will try to make up for that in this post.
- Turn on receiver
- Wait for IRQ to indicate data available
- While RSSI bit in status word is set keep reading data as IRQ indicates it is coming in
- Reset FIFO
The example code in the datasheet looks for an end-of-packet marker in step 3, which is also a workable option but has the disadvantage that the packet marker can never appear anywhere else in the packet. If your packets contain arbitrary data it’s possible an end-of-packet sequence like 0xAA55AA55 might appear in them, making those particular ones impossible to transmit. Instead I look for RSSI dropping and then decode what I have in the buffer independently of exactly how many bytes were received.
Step 4 is also rather critical. Without it you will keep getting IRQs signalling new data in the FIFO. The RFM12B picks up the preamble bytes which start the FIFO filling but does not seem to have any mechanism for stopping it again. You have to send the reset commands given in the datasheet or it will just keep receiving crap, even once RSSI disappears and it should be obvious that no new valid data is going to arrive.