Skip to content

Instantly share code, notes, and snippets.

@JyeSmith
Last active March 23, 2024 23:04
Show Gist options
  • Save JyeSmith/59043edc8ff3d03209c94e3da51de09b to your computer and use it in GitHub Desktop.
Save JyeSmith/59043edc8ff3d03209c94e3da51de09b to your computer and use it in GitHub Desktop.
RX5808 set freq example
#include <SPI.h>
#define SPI_ADDRESS_SYNTH_B 0x01
#define PIN_SPI_SLAVE_SELECT 22
#define RSSIA_PIN 36
#define RSSIB_PIN 39
uint16_t freq = 5740;
void setup() {
Serial.begin(9600);
pinMode(RSSIA_PIN, INPUT);
pinMode(RSSIB_PIN, INPUT);
pinMode(PIN_SPI_SLAVE_SELECT, OUTPUT);
digitalWrite(PIN_SPI_SLAVE_SELECT, HIGH);
SPI.begin();
}
void loop() {
rxWrite(SPI_ADDRESS_SYNTH_B, getSynthRegisterBFreq(freq));
delay(100);
Serial.print(freq);
Serial.print(", ");
Serial.print(analogRead(RSSIA_PIN));
Serial.print(", ");
Serial.println(analogRead(RSSIB_PIN));
freq += 20;
if (freq > 5880) {
freq = 5740;
}
delay(2000);
}
void rxWrite(uint8_t addressBits, uint32_t dataBits) {
uint32_t data = addressBits | (1 << 4) | (dataBits << 5);
SPI.beginTransaction(SPISettings(1000000, LSBFIRST, SPI_MODE0));
digitalWrite(PIN_SPI_SLAVE_SELECT, LOW);
SPI.transferBits(data, NULL, 25);
digitalWrite(PIN_SPI_SLAVE_SELECT, HIGH);
SPI.endTransaction();
}
uint16_t getSynthRegisterBFreq(uint16_t f) {
return ((((f - 479) / 2) / 32) << 7) | (((f - 479) / 2) % 32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment