Post Go back to editing

Need Help in Connecting ADF5356 EVK to ESP32 (Hardware Connections) + Need verificcation of my written frequency locking code.

Category: Hardware
Product Number: ADF5356

Hi Analog Devices Team,

can you please give hardware connection guidelines with ESP32 via SPI? Though I have a clarity in that connections, but still for safer side I want to know the connections. I am going with ESP32 to connect with ADF5356 EVK to store the registers in ESP32 memory such that if whole PLL device reboots also the registers stored in the ESP32 should write to PLL.

I am attaching the code as well for the review from Analog Devices Team. can you please verify it give me suggestions accordingly. We are running out of time please support.

#include <SPI.h>

#include <Preferences.h> // For non-volatile storage

 

// Pin definitions (adjust based on your wiring)

#define ADF5356_LE 19   // Latch Enable (SPI Chip Select)

#define ADF5356_CE 5    // Chip Enable (optional)

#define ADF5356_MUXOUT 4 // For lock detection (optional)

 

// Constants for 8.25 GHz with 122.88 MHz reference

const uint32_t REF_FREQ = 122880000;  // 122.88 MHz in Hz

const uint64_t TARGET_FREQ = 8250000000; // 8.25 GHz in Hz

const uint8_t RF_DIVIDER = 1;          // No division (full frequency)

 

// Register values calculated for 8.25 GHz output

// (Calculated using ADIsimPLL with 122.88 MHz reference)

const uint32_t ADF5356_REGISTERS[13] = {

  0x00580005,  // R0: Control bits + integer divider

  0x2000A3E9,  // R1: Fractional divider (LSB)

  0x00008002,  // R2: Fractional divider (MSB)

  0x00004E42,  // R3: Phase adjust

  0x00000004,  // R4: RF output control

  0x008B25A4,  // R5: N divider

  0x00000006,  // R6: MUX control

  0x00000007,  // R7: Reference counter

  0x00014007,  // R8: Phase resync

  0x00612009,  // R9: VCO band select

  0x0000050A,  // R10: Lock detect

  0x0000001B,  // R11: Misc control

  0x0000000C   // R12: Output power

};

 

Preferences nvs; // Non-volatile storage object

 

void writeADF5356Register(uint32_t value) {

  /* Writes a 32-bit value to the ADF5356 via SPI */

 

  digitalWrite(ADF5356_LE, LOW); // Begin SPI transaction

 

  // Transfer 4 bytes (MSB first)

  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));

  SPI.transfer((value >> 24) & 0xFF); // Byte 3 (MSB)

  SPI.transfer((value >> 16) & 0xFF); // Byte 2

  SPI.transfer((value >> 8) & 0xFF);  // Byte 1

  SPI.transfer(value & 0xFF);         // Byte 0 (LSB)

  SPI.endTransaction();

 

  // Latch the data into the register

  digitalWrite(ADF5356_LE, HIGH);

  delayMicroseconds(1); // tLEH minimum 20ns (1us for safety)

  digitalWrite(ADF5356_LE, LOW);

}

 

bool checkLockStatus() {

  /* Optional function to verify PLL lock status */

  return digitalRead(ADF5356_MUXOUT) == HIGH; // HIGH means locked

}

 

void initializeADF5356() {

  /* Initializes the ADF5356 with all required registers */

 

  // Check if we've already initialized (persistent across reboots)

  if(nvs.getBool("initialized", false)) {

    Serial.println("PLL already initialized - skipping full programming");

    return;

  }

 

  Serial.println("Programming ADF5356 registers...");

 

  // Write all registers in reverse order (12 down to 0)

  for(int i = 12; i >= 0; i--) {

    writeADF5356Register(ADF5356_REGISTERS[i]);

    delay(10); // Short delay between writes

  }

 

  // Mark as initialized in non-volatile storage

  nvs.putBool("initialized", true);

  Serial.println("ADF5356 programming complete");

}

 

void setup() {

  // Initialize serial for debugging

  Serial.begin(115200);

  delay(1000); // Wait for serial to initialize

 

  // Initialize non-volatile storage

  nvs.begin("pll_config");

 

  // Initialize GPIO pins

  pinMode(ADF5356_LE, OUTPUT);

  pinMode(ADF5356_CE, OUTPUT);

  pinMode(ADF5356_MUXOUT, INPUT); // For lock detection

 

  // Set initial states

  digitalWrite(ADF5356_LE, LOW);

  digitalWrite(ADF5356_CE, HIGH); // Enable PLL

 

  // Initialize SPI (CLK=18, MOSI=23, MISO not used)

  SPI.begin(18, 23, -1, -1);

 

  // Initialize the ADF5356

  initializeADF5356();

 

  // Optional: Verify lock status

  if(checkLockStatus()) {

    Serial.println("PLL Locked at 8.25 GHz");

  } else {

    Serial.println("Warning: PLL lock not detected");

  }

 

  Serial.println("Setup complete");

}

 

void loop() {

  // Main loop can monitor lock status or handle adjustments

  static unsigned long lastCheck = 0;

 

  if(millis() - lastCheck > 1000) { // Check every second

    lastCheck = millis();

   

    if(!checkLockStatus()) {

      Serial.println("PLL lost lock - reinitializing");

      initializeADF5356(); // Attempt to relock

    }

  }

}

I hope will receive the earliest response.

Thanks