I all, i'm newbee in arduino so..
my problem :
i used tu run a skectch on uno, nano and min pro. this sketch (i'm not the author) run perfectly in all the world todrive ADF4351 and others.
but, if i run it on an atmega2560 it does not work at all. i changed the pin numbers for the spi communication, but no way.
this is the code for uno :
#include <SPI.h>
long int r0, r1, r2, r3, r4, r5; //registres ADF435x
int A ; //etat chargement frequence 1 fait_pas fait
int B ; //etat chargement frequence 2 fait_pas fait
int C ; //etat chargement frequence 3 fait_pas fait
int D ; //etat chargement frequence 4 fait_pas fait
void writePLL(uint32_t PLLword) { // cette routine balance un mot de 32 bits dans l'ADF4351
Serial.println("ecriture du registre");
// msb (b31) first, lsb (b0) last
for (byte flop=32; flop>0; flop--) { // PLL est de 32 bits
(PLLword & 0x80000000? PORTB |= 0b00001000 : PORTB &= 0b11110111); // AND avec MSB pour sortir un '1' ou un '0' sur PB3 = '11'
PORTB |= 0b00010000; // CLK à 1 (PB4 = 1)
PORTB &= 0b11101111; // CLK à 0 (PB4 = 0)
PLLword <<= 1; // rotation à gauche pour le prochain bit
}
PORTB |= 0b00000100; // on mémorise sur le front montant de LE (PB2 = 1)
PORTB &= 0b11111011; // on remet LE à 0 (PB2 = 0)
}
////////////////////////////////////////////////////////////////////////////
void setup () {
Serial.begin(9600);//pour suivre les infos sur le terminal
pinMode(5, INPUT_PULLUP); // choix du canal
pinMode(6, INPUT_PULLUP); // choix du canal
pinMode(3, INPUT_PULLUP); // choix de la référence
pinMode(11, OUTPUT); //DATA
pinMode(12, OUTPUT); // CLK
pinMode(10, OUTPUT); // LE
pinMode(4, OUTPUT); // état bit E
A=0; // Canal 1 chargé ou pas
B=0; // Canal 2 chargé ou pas
C=0; // Canal 3 chargé ou pas
D=0; // Canal 4 chargé ou pas
}
and then loop()
now the code the same code for atmega :
#include <SPI.h>
long int r0, r1, r2, r3, r4, r5; //registres ADF435x
int A ; //etat chargement frequence 1 fait_pas fait
int B ; //etat chargement frequence 2 fait_pas fait
int C ; //etat chargement frequence 3 fait_pas fait
int D ; //etat chargement frequence 4 fait_pas fait
void writePLL(uint32_t PLLword) { // cette routine balance un mot de 32 bits dans l'ADF4351
Serial.println("ecriture du registre");
//digitalWrite(SS, LOW); // ensure SS stays high for now
// msb (b31) first, lsb (b0) last
for (byte flop=32; flop>0; flop--) { // PLL est de 32 bits
(PLLword & 0x80000000? PORTB |= 0b00001000 : PORTB &= 0b11110111); // AND avec MSB pour sortir un '1' ou un '0' sur PB3 = '11'
PORTB |= 0b00010000; // CLK à 1 (PB4 = 1)
PORTB &= 0b11101111; // CLK à 0 (PB4 = 0)
PLLword <<= 1; // rotation à gauche pour le prochain bit
}
PORTB |= 0b00000100; // on mémorise sur le front montant de LE (PB2 = 1)
PORTB &= 0b11111011; // on remet LE à 0 (PB2 = 0)
}
////////////////////////////////////////////////////////////////////////////
void setup () {
//digitalWrite(SS, LOW); // ensure SS stays high for now
//SPI.begin ();
// Slow down the master a bit
// SPI.setClockDivider(SPI_CLOCK_DIV8);
Serial.begin(9600);//pour suivre les infos sur le terminal
pinMode(5, INPUT_PULLUP); // choix du canal
pinMode(6, INPUT_PULLUP); // choix du canal
pinMode(3, INPUT_PULLUP); // choix de la référence
pinMode(51, OUTPUT); //DATA
pinMode(52, OUTPUT); // CLK
pinMode(53, OUTPUT); // LE
pinMode(4, OUTPUT); // état bit E
A=0; // Canal 1 chargé ou pas
B=0; // Canal 2 chargé ou pas
C=0; // Canal 3 chargé ou pas
D=0; // Canal 4 chargé ou pas
}
then loop()
i tried many differents wiring positions and all the 3 spi connectors, but i can't drive any ADF4351.
What am i wrong? if anybody can help it will be great.
Many thanks.