A short bit of background: over the years, I've made a few wireless temperature transmitter devices based around a PICAXE-14M2 microcontroller and 433MHz wireless module, and these last many years powered from 2xAA batteries. I've also made a number of different display devices to receive and display the temperatures including the PICAXE-based one below.
These devices all use the PICAXE rfout and rfin commands. I've also made some displays that aren't PICAXE and those use the NKM2401 for reception duties.
I wanted to start making some more advanced devices to fit in with this "ecosystem", starting with a transmitter with built in bare glass LCD display that would also be battery powered. To get the power consumption down to the lowest possible level, it wasn't practical to use a dedicated LCD driver plus PICAXE or an LCD-driving microcontroller plus NKM2401, so I started investigating how to replicate the protocol myself.
The details given in the NKM2401 datasheet and any PICAXE documentation is very vague and shows a "waveform" with 8 bytes along with mentions of Manchester encoding, a 200us period, and a "CRC".
Protocol reverse-engineering
I set up an NKM2401 on breadboard and sent a few data packets with the logic analyser connected to the serial input and Manchester data output.
From inspection of the waveform, we can see that each half bit is indeed exactly 200us and the packet format is as follows:
With that confirmed, that's all the information needed to re-implement the packet.
Here is a clearer view of the packet. This one is actually generated by my re-implementation rather than the NKM2401. The yellow line shows the values of the data bytes and CRC.
The re-implementation works and my finished PIC16LF1936-based transmitter project (photo attached) works with all the other receivers in the system. Idle current consumption is less than 10uA.
This post isn't meant to have detailed information about implementing the protocol on specific microcontrollers since this is the PICAXE Forum after all. I might come back and add another post with more implementation tips later, but the main things to keep in mind are:
These devices all use the PICAXE rfout and rfin commands. I've also made some displays that aren't PICAXE and those use the NKM2401 for reception duties.
I wanted to start making some more advanced devices to fit in with this "ecosystem", starting with a transmitter with built in bare glass LCD display that would also be battery powered. To get the power consumption down to the lowest possible level, it wasn't practical to use a dedicated LCD driver plus PICAXE or an LCD-driving microcontroller plus NKM2401, so I started investigating how to replicate the protocol myself.
The details given in the NKM2401 datasheet and any PICAXE documentation is very vague and shows a "waveform" with 8 bytes along with mentions of Manchester encoding, a 200us period, and a "CRC".
Protocol reverse-engineering
I set up an NKM2401 on breadboard and sent a few data packets with the logic analyser connected to the serial input and Manchester data output.
From inspection of the waveform, we can see that each half bit is indeed exactly 200us and the packet format is as follows:
- One-byte preamble of 0x00
- Constant byte of 0x09
- 8 data bytes in the same order as the input bytes, with no processing, scrambling or further encoding
- CRC – and this is indeed a CRC (more on that next) not a simple checksum
- Polynomial=0xb3
- Initial value=0x00
- Reflect input=false
- Reflect output=false
- Xorout=0x00
- Check=0xdc
- Residue=0x00
With that confirmed, that's all the information needed to re-implement the packet.
Here is a clearer view of the packet. This one is actually generated by my re-implementation rather than the NKM2401. The yellow line shows the values of the data bytes and CRC.
The re-implementation works and my finished PIC16LF1936-based transmitter project (photo attached) works with all the other receivers in the system. Idle current consumption is less than 10uA.
This post isn't meant to have detailed information about implementing the protocol on specific microcontrollers since this is the PICAXE Forum after all. I might come back and add another post with more implementation tips later, but the main things to keep in mind are:
- The 200us half-bit interval should be recreated exactly (I haven't investigated exactly how tolerant the NKM2401 and PICAXE are to any deviations)
- Use a logic analyser to check your timings as C compiler bloat (and MPLAB Melody delay function bloat) will easily add significant delays between each bit and each byte, and you'll need to tweak your timings to suit
- The transmission and CRC routines are probably best written in assembly if using an 8-bit PIC. The '
' instruction (rotate left through carry) is very useful for both and there's no nice C equivalent as far as I knowCode:
rlf