This is a portable, hardware-agnostic C driver for the RFM69HCW / SX1231 RF transceiver. Originally built for STM32 (HAL), it can now be easily ported to any microcontroller (ESP32, Arduino, Raspberry Pi Pico...) without touching the core logic, thanks to a lightweight MCAL (Microcontroller Abstraction Layer).
This library provides a way of controlling the radio module over SPI, configuring packet or raw modes.
To help you understand or modify the project, the documentation has been split into detailed sections:
- 💻 RFM69HCW Packet Mode Details — Understand how to make a simple communication using Packet Mode
- 📊 RFM69HCW RAW Mode Details — Understand how to use RAW Mode
- 🔒 Payload Encryption Guide — How to secure your data using external cryptographic libraries.
- 🪲 Debug — Simple Debug Implementation
- 🚨 TroubleShooting — Many response to a lot of error...
RFM69_WriteReg→ Write a value in a registerRFM69_ReadReg→ Read a register value
Full reference
| Core API | Description | Example |
|---|---|---|
RFM69_WriteReg |
Write a value in a register | RFM69_WriteReg(0x37, 0x90); |
RFM69_ReadReg |
Read a value in a register | uint8_t currentVal = RFM69_ReadReg(0x02); |
RFM69_Init→ Initialize SPI interface and Chip Select pinRFM69_SetMode→ Select operating mode typeRFM69_GetMode→ Get operating mode
Full reference
| Radio Initialization | Description | Example/Available Modes |
|---|---|---|
RFM69_Init |
Initialize SPI interface and Chip Select pin | RFM69_Init(&hspi1, GPIOC, GPIO_PIN_7); |
RFM69_SetMode |
Select operating mode type | RFM69_MODE_SLEEPRFM69_MODE_STDBY RFM69_MODE_FS RFM69_MODE_TX RFM69_MODE_RX |
RFM69_GetMode |
Get operating mode | Return RFM69_Mode_t :RFM69_MODE_SLEEPRFM69_MODE_STDBY RFM69_MODE_FS RFM69_MODE_TX RFM69_MODE_RX |
RFM69_SetFrequencyTo433→ Set Frequency to 433 MHzRFM69_SetBitrate→ Set bitrate of communicationRFM69_GetBitrate→ Get bitrate of communicationRFM69_AutoSetFdev→ Automatically adjusts frequency deviation based on bitrate for FSK ModulationRFM69_GetFdev→ Get frequency deviation based on bitrate with FSK ModulationRFM69_SetModulationType→ Set modulation typeRFM69_GetModulationType→ Get modulation typeRFM69_SetDataProcessingMode→ Set Data Processing typeRFM69_GetDataProcessingMode→ Get Data Processing typeRFM69_SetDataShaping→ Set Data Shaping typeRFM69_GetDataShaping→ Get Data Shaping typeRFM69_WaitForPLLLock→ Wait For PLL LockRFM69_WaitForTxReady→ Wait For Tx Mode Ready
Full reference
| Radio Configuration | Description | Example/Available Modes |
|---|---|---|
RFM69_SetFrequencyTo433 |
Set Frequency to 433 MHz | |
RFM69_SetBitrate |
Set bitrate of communication : 4.8 kbps = 4800 |
RFM69_SetBitrate(4800); |
RFM69_GetBitrate |
Get bitrate of communication | uint32_t Bitrate = RFM69_GetBitrate(); |
RFM69_AutoSetFdev |
Automatically adjusts frequency deviation based on bitrate for FSK Modulation | RFM69_AutoSetFdev(); |
RFM69_GetFdev |
Get frequency deviation based on bitrate | uint32_t Fdev = RFM69_GetFdev(); |
RFM69_SetModulationType |
Set Modulation type | RFM69_MODUL_FSKRFM69_MODUL_OOK |
RFM69_GetModulationType |
Get Modulation type | RFM69_Modulation_t RFM69_GetModulationType(void) |
RFM69_SetDataProcessingMode |
Select Data Processing type | RFM69_PACKET_MODERFM69_CONTINUOUS_SYNC RFM69_CONTINUOUS_RAW |
RFM69_GetDataProcessingMode |
Get Data Processing type | RFM69_DataProcessingMode_t RFM69_GetDataProcessingMode(void) |
RFM69_SetDataShaping |
Select Data Shaping type | RFM69_SHAPING_NONERFM69_SHAPING_Gaussianfilter_BT1RFM69_SHAPING_Gaussianfilter_BT05RFM69_SHAPING_Gaussianfilter_BT03 |
RFM69_GetDataShaping |
Get Data Shaping type | RFM69_Data_Shaping_t RFM69_GetDataShaping(void) |
RFM69_WaitForPLLLock |
Wait For PLL Lock | |
RFM69_WaitForTxReady |
Wait For Tx Mode Ready |
RFM69_SetKeyValues_Sync→ Set Key to link two modules.RFM69_SetPacketConfig→ Select Packet ConfigurationRFM69_AutoMessageDetectionReceive_Config→ Select Automatic Receive Packet ConfigurationRFM69_FlushFIFO→ Flush FIFORFM69_SendMessage_Packet_Mode→ Send messageRFM69_ReceiveMessage_Packet_Mode→ Read a message received
Full reference
| Modulation & Packet Engine | Description | Example/Available Modes |
|---|---|---|
RFM69_SetKeyValues_Sync |
Set Key to link two modules. Must be identical on both modules Max key length 8 |
uint8_t mykey[] = {0x42, 0x24}; RFM69_SetSyncValues(mykey, 2); |
RFM69_SetPacketConfig |
Select Packet Configuration | RFM69_PACKET_FORMAT_FIXEDRFM69_PACKET__FORMAT_VARIABLERFM69_DC_FREE_NONERFM69_DC_FREE_MANCHESTERRFM69_DC_FREE_WHITENINGRFM69_CRC_OFFRFM69_CRC_ONRFM69_CRC_AUTOCLEAR_ONRFM69_CRC_AUTOCLEAR_OFFRFM69_FILTER_NONERFM69_FILTER_NODERFM69_FILTER_NODE_BROADCAST |
RFM69_AutoMessageDetectionReceive_Config |
Choose type of syncing between two module | RFM69_SYNC_OFFRFM69_SYNC_ONRFM69_FIFO_FILL_IF_SYNCRFM69_FIFO_FILL_ALWAYSRFM69_SYNC_TOLERANCE_ERROR_0RFM69_SYNC_TOLERANCE_ERROR_1RFM69_SYNC_TOLERANCE_ERROR_2RFM69_SYNC_TOLERANCE_ERROR_3RFM69_SYNC_TOLERANCE_ERROR_4RFM69_SYNC_TOLERANCE_ERROR_5RFM69_SYNC_TOLERANCE_ERROR_6RFM69_SYNC_TOLERANCE_ERROR_7 |
RFM69_FlushFIFO |
Flush FIFO | |
RFM69_SendMessage_Packet_Mode |
Send message uint8_t message[] = "SATELLITE_TEST"; RFM69_SendMessage( message, 14); |
|
RFM69_ReceiveMessage_Packet_Mode |
Read a message received | uint8_t receivedLen = RFM69_ReceiveMessage_Packet_Mode(rxBuffer, 64); |
RFM69_SetDefaultDioMapping→ Set DIO Mapping Default (Important if you use RAW Mode)RFM69_Text_To_Binary_Payload→ Transform Text to Binary formatRFM69_RAW_FillUp_Playload→ Fill Up Playload before sendingRFM69_RAW_DATA_SEND→ Automatic Send Message in RAW ModeRFM69_RAW_Transmit_Byte→ Transmit byte over radio with bit stuffingRFM69_RAW_CRC16_Calculation_Buffer→ Calculate CRC16 for error checkRFM69_Pad_To_256→ Complete Data buffer to be up to 256 bytesCRC_CHECK→ CRC Check
Full reference
| Function | Description | Example/Available Modes |
|---|---|---|
RFM69_SetDefaultDioMapping |
Set DIO Mapping Default (Important if you use RAW Mode) | By default DIO1 is DCLK (Clock) |
RFM69_Text_To_Binary_Payload |
Transform Text to Binary format | |
RFM69_RAW_FillUp_Payload |
Fill Up Playload before sending | |
RFM69_RAW_DATA_SEND |
Automatic Send Message in RAW Mode | |
RFM69_RAW_Transmit_Byte |
Transmit byte over radio with bit stuffing | void RFM69_RAW_Transmit_Byte(uint8_t data, uint8_t enable_stuffing) |
RFM69_RAW_CRC16_Calculation_Buffer |
Calculate CRC16 for error check | |
RFM69_Pad_To_256 |
Complete Data buffer to be up to 256 bytes | |
CRC_CHECK |
CRC Check |
RFM69_PowerAmplifierSelection→ Select Power Amplifier type Pout = PA_... + OutputPower [dBm]RFM69_GetPowerAmplifier→ Get Power Amplifier type
Full reference
| Transmission | Description | Example/Available Modes |
|---|---|---|
RFM69_PowerAmplifierSelection |
Select Power Amplifier type Pout = PA_... + OutputPower [dBm] |
PA_0 => Start from -18 to +13 dbm PA_1 => Start from -18 to +13 dbmPA_1_2 => Start from -14 to +17 dbm PA_HIGH_POWER => Start from -11 to +20 dbm |
RFM69_GetPowerAmplifier |
Get Power Amplifier type | RFM69_PA_Select_t RFM69_GetPowerAmplifier(void) |
RFM69_RSSI→ Visualize RSSI in dBmRFM69_SetLnaImpedance→ Set LNA Impedance (Z) InRFM69_SetLnaGain→ Set LNA GainRFM69_GetLnaStatus→ Get LNA ConfigurationRFM69_StartAFC→ Start Frequency Recalibration AFCRFM69_Status_RecalibrationFrequencyAFC→ Get Status of the Automatic Recalibration Frequency Correction AFCRFM69_GetAFCCorrectionHz→ Read AFC Correction in HzRFM69_ClearAfc→ Clear Frequency Recalibration AFCRFM69_SetAfcAuto→ Activate/Deactive Automatic Frequency Recalibration AFCRFM69_SetAfcAutoclear→ Activate/Deactive Clearing Automatic Frequency Recalibration AFCRFM69_StartFEI→ Start Measurement Of Error Frequency in Hz FEIRFM69_Status_ReadingErrorFrequency→ Get Status of the Reading Error Frequency FEIRFM69_GetFrequencyErrorFeiHz→ Read Error Frequency in Hz FEI
Full reference
| Reception | Description | Example/Available Modes |
|---|---|---|
RFM69_RSSI |
Visualize RSSI in dBm | Return an uint8_t ; |
RFM69_SetLnaImpedance |
Set LNA Impedance (Z) In | LNA_Impedance_50LNA_Impedance_200 |
RFM69_SetLnaGain |
Set LNA Gain | LNA_GAIN_AUTOLNA_GAIN_G1LNA_GAIN_G2LNA_GAIN_G3LNA_GAIN_G4LNA_GAIN_G4LNA_GAIN_G5LNA_GAIN_G6 |
RFM69_GetLnaStatus |
Get LNA Configuration | |
RFM69_StartAFC |
Start Frequency Recalibration AFC | |
RFM69_Status_RecalibrationFrequencyAFC |
Get Status of the Automatic Recalibration Frequency Correction AFC | |
RFM69_GetAFCCorrectionHz |
Read AFC Correction in Hz | |
RFM69_ClearAfc |
Clear Frequency Recalibration AFC | |
RFM69_SetAfcAuto |
Activate/Deactive Automatic Frequency Recalibration AFC | AFC_AUTO_OFFAFC_AUTO_ON |
RFM69_SetAfcAutoclear |
Activate/Deactive Automatic Frequency Recalibration AFC | AFC_AUTOCLEAR_OFFAFC_AUTOCLEAR_ON |
RFM69_StartFEI |
Start Measurement Of Error Frequency in Hz FEI | |
RFM69_Status_ReadingErrorFrequency |
Get Status of the Reading Error Frequency FEI | |
RFM69_GetFrequencyErrorFeiHz |
Read Error Frequency in Hz FEI |
The SPI was configured as follows:
- Frame Format : Motorola
- Mode : Full-Duplex Master
- CPOL : Low
- CPHA : 2 Edge
- First Bit : MSB First
Porting this driver to a new platform requires zero modifications to the RFM69HCW.c file. Everything happens in the header configuration (MCAL_RFM69HCW.h).
You simply need to map the MCAL_RFM69H_... macros to your new platform's specific libraries.
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
To use the printf debug feature on STM32, make sure you have redirected stdout to your UART peripheral (by overriding the _write function).
