Re: Question ....


Brian Flynn GM8BJF
 

Hi again Gordon,
Just realised I left a bit off the end of the code when copying and pasing it  Here it is again.

_______________________________________________________________________________
/*
******************************************************
* Sketch for controlling an AD ADF4351 synthesiser
* over its SPI bus.
*                                                          
* This module uses the Arduino SPI library (comes bundled with 
* the Arduino IDE) to enable communication between an
* Arduino program and an SPI  enabled peripheral chip.    
*                                                          
* The routine reads in the hex vales from the sketch and sends
* them to the chip. The hex programming values can be generated
* in the AD programme "Int-N PLL Software" which can be
* downloaded here http://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/EVAL-ADF4113.html#eb-overview
*                                                           
* The SPI library uses pin 13 of the Arduino Uno for clock. 
* Serial data is sent out on pin 11.                                                          
* This routine uses pin 10 as the chip select for the    
* SPI device to be programmed.                                                               
******************************************************
*/
#include <SPI.h>                            //  Links prewritten SPI library into the code
#include <avr/sleep.h>
#define interruptPin 2
void setup()
{
  pinMode(10, OUTPUT);                //  Set SPI pins to be outputs
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(13, HIGH);

  Serial.begin(115200);
  pinMode(LED_BUILTIN,OUTPUT);
  pinMode(interruptPin,INPUT_PULLUP);
  digitalWrite(LED_BUILTIN,HIGH);
 
  SPI.begin();                            //  Initialize SPI parameters
  SPI.setBitOrder(MSBFIRST);              //  MSB to be sent first
  SPI.setDataMode(SPI_MODE0);             //  Set for SPI Mode 0
  SPI.setClockDivider(SPI_CLOCK_DIV128);   //  Set clock divider (optional)

                                         

  digitalWrite(10,LOW);         //  Drop chip-select to 0
  SPI.transfer(0x00);          //  Do SPI transfer of R5
  SPI.transfer(0x58);
  SPI.transfer(0x00);
  SPI.transfer(0x05);
  digitalWrite(10,HIGH);       //  Raise chip-select to 1
  digitalWrite(10,LOW);         
  SPI.transfer(0x00);               //  Do SPI transfer of R4
  SPI.transfer(0xEA);
  SPI.transfer(0x00);
  SPI.transfer(0x3C);
  digitalWrite(10,HIGH);       //  Raise chip-select to 1
  digitalWrite(10,LOW);         
  SPI.transfer(0x00);               //  Do SPI transfer of R3
  SPI.transfer(0x00);
  SPI.transfer(0x04);
  SPI.transfer(0xB3);
  digitalWrite(10,HIGH);       //  Raise chip-select to 1
  digitalWrite(10,LOW);         
  SPI.transfer(0x1A);               //  Do SPI transfer of R2
  SPI.transfer(0x00);
  SPI.transfer(0x58);
  SPI.transfer(0x42);
  digitalWrite(10,HIGH);       //  Raise chip-select to 1
  digitalWrite(10,LOW);         
  SPI.transfer(0x00);               //  Do SPI transfer of R1
  SPI.transfer(0x01);
  SPI.transfer(0x80);
  SPI.transfer(0x29);
  digitalWrite(10,HIGH);       //  Raise chip-select to 1
  digitalWrite(10,LOW);         
  SPI.transfer(0x00);               //  Do SPI transfer of R0
  SPI.transfer(0X56);
  SPI.transfer(0x00);
  SPI.transfer(0x20);
  digitalWrite(10,HIGH);       //  Raise chip-select to 1
 
  delay(1000);                 //  Delay loop 1 seconds (pick your time frame)
                            
}
void loop()
{
  delay(5000);
  Going_To_Sleep();
}

void Going_To_Sleep() {
  sleep_enable();
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  digitalWrite(LED_BUILTIN,LOW);
  delay(1000);
  sleep_cpu();

}

________________________________________________________________

73s
Brian GM8BJF

Join UKMicrowaves@groups.io to automatically receive all group messages.