#include #include "common.h" // XXX - ADF4350 LE // PB2 - SCK to ADF4350 CLK // PB1 - DO (MOSI) to ADF4350 DATA // XXX - ADF4350 LD String tosend="Test"; void Delay(uint32_t); uint8_t SendReceiveSPIData(uint8_t); void SendSPIDataADF4350 (uint32_t); void spi_setup() { // set direction of PB1 (DO) and PB2 (USCK) as output DDRB=(1<> 24; uint8_t byte2 = (outval & 0x00FF0000) >> 16; uint8_t byte3 = (outval & 0x0000FF00) >> 8; uint8_t byte4 = outval & 0x000000FF; // send these to the ADF4350 via SPI SendReceiveSPIData (byte1); SendReceiveSPIData (byte2); SendReceiveSPIData (byte3); SendReceiveSPIData (byte4); uint8_t lout = 0; // Loop waiting for the the SPI BSY flag to go low while (lout == 0) { // Read the SPI status register uint32_t statusSPI = *(uint32_t *)(SPI1_BASE + 0x08); // Just bit 7 the SPI BSY flag - wait for this to go low then leave this function statusSPI &= BIT_7; // The condition has been met so signal to get out of this loop if (statusSPI == 0) lout = 1; } // Add a delay here so the clock has gone low before LE is taken high Delay(10); // Take LE high to load the data into the register *(uint32_t *)(GPIOA_BASE + 0x10) = BIT_2; // Short delay while LE is high (minimum of 20ns) Delay(30); // Take LE low again *(uint32_t *)(GPIOA_BASE + 0x14) = BIT_2; }