diff --git a/main.c b/main.c index afc305e..b7aab9d 100644 --- a/main.c +++ b/main.c @@ -2,8 +2,8 @@ #include "common.h" // PB3 - ADF4350 LE -// PB2 - SCK to ADF4350 CLK -// PB1 - DO (MOSI) to ADF4350 DATA +// PB2 - USCK to ADF4350 CLK +// PB1 - DO to ADF4350 DATA // PB0 - ADF4350 LD // PB4 - Lock Status LED @@ -13,7 +13,7 @@ void SendSPIDataADF4350 (uint32_t); int main() { - // set instructions to configure the ADF4350 for a 1 GHz +5dBm output + // Set instructions to configure the ADF4350 for a 1 GHz +5dBm output. uint32_t ar0=0x500000; uint32_t ar1=0x8008011; uint32_t ar2=0x4e42; @@ -21,7 +21,7 @@ int main() uint32_t ar4=0xac803c; uint32_t ar5=0x580005; - // alternative instructions for a 1001.25 MHz +5dBm output + // Alternative instructions for a 1001.25 MHz +5dBm output. //uint32_t ar0=0x500008; //uint32_t ar1=0x8008029; //uint32_t ar2=0x4e42; @@ -29,41 +29,58 @@ int main() //uint32_t ar4=0xac803c; //uint32_t ar5=0x580005; - // set direction of PB1 (DO) and PB2 (USCK) as output - DDRB=(1<> i) & 0x01; // write data bytes in Data register, will cause them to get sent on clock - while(USIOIF==0) // check USI data counter overflow flag to detect the end of transmission every byte + ///USIDR = value[i]; // Wrong way to do it apparently, still saving for future reference + USIDR = (value >> i) & 0x01; // Write data bytes in Data register, will cause them to get sent on clock + while(USIOIF==0) // heck USI data counter overflow flag to detect the end of transmission every byte { - USICR|=(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 + // Send these to the ADF4350 via SPI SendReceiveSPIData (byte1); SendReceiveSPIData (byte2); SendReceiveSPIData (byte3); SendReceiveSPIData (byte4); - // 2 x 16 version: + // 2 x 16 version (for reference): // split into 2 x 16 bit words ///uint16_t highWord = (outval & 0xffff0000) >> 16; ///uint16_t lowWord = outval & 0x0000ffff; @@ -127,12 +146,16 @@ void SendSPIDataADF4350 (uint32_t outval) ///SendReceiveSPIData (highWord); ///SendReceiveSPIData (lowWord); - // delay so the clock has gone low before LE is taken high + // Delay to make sure the clock has gone low before LE is taken high. Delay(10); - // pull LE high to load the data into the ADF4350 register - PORTB |= (1 << PORTB3); - // short delay while LE is high (minimum of 20ns) - Delay(30); - // pull LE low again - PORTB &= ~(1 << PORTB3); + + // Pull LE high to load the data into the ADF4350 register. + PORTB |= (1 << PB3); + + // Short delay while LE is high (minimum of 20ns). + // This is to make sure the ADF4350 has time to register bits. + Delay(100); + + // Pull LE low again. + PORTB &= ~(1 << PB3); } \ No newline at end of file