Last active
November 30, 2021 07:39
-
-
Save JyeSmith/78f83cec85d7c6c5b611ed2ecc8d1ff0 to your computer and use it in GitHub Desktop.
RTC6705_setFrequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <SPI.h> | |
#define SYNTHESIZERREGISTERA 0x00 | |
#define SYNTHESIZERREGISTERB 0x01 | |
#define SYNTHESIZERREGISTERC 0x02 | |
#define RFVCODFCCONTROLREGISTER 0x03 | |
#define VCOCONTROLREGISTER 0x04 | |
#define VCOCONTROLREGISTERCONT 0x05 | |
#define AUDIOMODULATORCONTROLREGISTER 0x06 | |
#define PREDRIVERANDPACONTROLREGISTER 0x07 | |
#define STATEREGISTER 0x0F | |
#define READ_BIT 0x00 | |
#define WRITE_BIT 0x01 | |
#define PIN_SPI_SLAVE_SELECT 5 | |
uint16_t freq = 5800; | |
static void rtc6705WriteRegister(uint32_t data) | |
{ | |
SPI.beginTransaction(SPISettings(10000000, LSBFIRST, SPI_MODE0)); | |
digitalWrite(PIN_SPI_SLAVE_SELECT, LOW); | |
SPI.transferBits(data, NULL, 25); | |
digitalWrite(PIN_SPI_SLAVE_SELECT, HIGH); | |
SPI.endTransaction(); | |
} | |
// https://github.com/betaflight/betaflight/blob/c56690786d9e601bd41a8adcc87a0428d967710d/src/main/drivers/vtx_rtc6705_soft_spi.c#L143 | |
void rtc6705WriteFrequency(uint32_t channel_freq) | |
{ | |
uint32_t freq = 25 * channel_freq; | |
uint32_t SYN_RF_N_REG = freq / 64; | |
uint32_t SYN_RF_A_REG = freq % 64; | |
uint32_t data = SYNTHESIZERREGISTERB | (WRITE_BIT << 4) | (SYN_RF_A_REG << 5) | (SYN_RF_N_REG << 12); | |
rtc6705WriteRegister(data); | |
} | |
void rtc6705ReadRegister(uint32_t reg) | |
{ | |
uint32_t data = reg | (READ_BIT << 4); | |
rtc6705WriteRegister(data); | |
} | |
void rtc6705ResetState() | |
{ | |
uint32_t data = STATEREGISTER | (WRITE_BIT << 4); | |
rtc6705WriteRegister(data); | |
} | |
void setup() | |
{ | |
Serial.begin(9600); | |
pinMode(PIN_SPI_SLAVE_SELECT, OUTPUT); | |
digitalWrite(PIN_SPI_SLAVE_SELECT, HIGH); | |
SPI.begin(); | |
// rtc6705ResetState(); | |
} | |
void loop() | |
{ | |
rtc6705WriteFrequency(freq); | |
// rtc6705ReadRegister(SYNTHESIZERREGISTERB); | |
Serial.println(freq); | |
freq += 20; | |
if (freq > 5880) { | |
freq = 5740; | |
} | |
delay(3000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment