0
\$\begingroup\$

I need to send a 12-bit data continuously from one system to another using 433MHz RF modules. The transmitter and receiver systems uses STM controllers (STM32L010F4) which are connected to the radio modules.

I understand that the modules use ASK and was initially under the impression that I only need to push the bits that I need to send to the transmitter's data pin; the module would take care of the rest. Hence I connected them to the UART peripheral's TX and RX pins. However some reading made me realize that in addition to the modulation, the data needs to encoded and framed in a particular way for reliable transmission.

The RadioHead ASK library apparently takes care of all this and the Arduino code is pretty straightforward. However, my controller has a very low flash memory size and there's no way to fit Arduino libs, STM32 core for Arduino and the RH_ASK library in it.

I'll have to write a low-footprint code myself.

From RH_ASK.h, the packet looks like this:

  • 36 bit training preamble consisting of 0-1 bit pairs
  • 12 bit start symbol 0xb38
  • 1 byte of message length byte count (4 to 30), count includes byte count and FCS bytes
  • n message bytes (including 4 bytes of header), maximum n is RH_ASK_MAX_MESSAGE_LEN + 4 (64)
  • 2 bytes FCS, sent low byte-hi byte

How do I generate the training preamble?

Apparently, I have to DC-balance modulate or Manchester encode the bits as well. Do I have to do this for the entire frame or just the data bytes?

Once I have the data bits generated, I was thinking of bit-banging them by using the UART port as normal GPIO (Normal UART would mess with the transmission as the packets as 8-bits wide?). This shouldn't be a hefty exercise. Is that all that I have to do, or am I missing something?

Also, can anyone provide me an ASK frame which I can use to test the hardware, before writing the library?

I don't mind going through the RH_ASK source code but I am on a tight deadline and would like to know if there are easy ways to get this done.

\$\endgroup\$
2
  • \$\begingroup\$ The quickest way to create some working code would be to run the Arduino implementation, then add print statements to dump out the traffic to & from the RF chip (or use a logic analyser); this will consist of initialisation commands, then repeating data transfers commands. Then write some STM32 code that just replicates the actions of the transmit code, and get comms running between that and an Arduino receiver. Finally implement the STM32 receiver. You'll this step-wise approach much quicker than re-coding everything, then trying to work out where the bugs are in the Tx or Rx code. \$\endgroup\$
    – jayben
    Nov 4, 2023 at 11:46
  • \$\begingroup\$ Using cheap 433 MHz modules is "possible" over very short distances (a few meters) and very "low speed". The shortest protocol I've used is sending alternate bits (at least 16) for startup and then sending the actual data. The entire sequence was repeated 3 times. At least one was correctly decoded. \$\endgroup\$
    – Antonio51
    Nov 4, 2023 at 15:05

1 Answer 1

1
\$\begingroup\$

How do I generate the training preamble?

alternating 1 and 0. For 36 bit long sequence, generate:

010101010101010101010101010101010101

Do I have to do this for the entire frame or just the data bytes?

It depends. For example, Texas Instruments for their CCxxxx MCU do not recommend Manchester encoding at all (link) but their MCU contains high tech radio in comparison with your setup (you do not specify precisely what modules do you use, so it is hard to estimate). While answer is not clear, I recommed using it. You should encode only message length, message body and checksum bytes. Do not encode training poreable (it already is encoded, but it is side effect) and do not encode start symbol because it is designed for having nice autocorelation properties and manchester encoding breaks it (more details: link).

Once I have the data bits generated, I was thinking of bit-banging them by using the UART port as normal GPIO (Normal UART would mess with the transmission as the packets as 8-bits wide?). This shouldn't be a hefty exercise. Is that all that I have to do, or am I missing something?

I recommend using precise timer and bitband instead of UART because UART peripherals generates start and stop bit which is unwanted for you, especially when using Manchester encoding. Some UART controllers adds delay between transmitting bytes but STM32 (with DMA used) is capable of transmitting without delays.

Also, can anyone provide me an ASK frame which I can use to test the hardware, before writing the library?

I recommend developing it without wireless modules. Instead of connecting GPIO output to wireless transmitter, connect it directly to GPIO input of the other MCU and test. You can use any valid packet. I recommed using packet which you will use at production.

I don't mind going through the RH_ASK source code but I am on a tight deadline and would like to know if there are easy ways to get this done.

I recommend spending some time by watching functional solution because implementing parser on the receiver side is not a trivial task.

ASK is the most trivial modulation and in many cases FSK work better. Depending on your needs, ASK still may be sufficient.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.