Dheeraj M Pai
/
SPORTMODE_ADF7023_IITMSAT
ADF7023 with Explanations
Revision 0:77ff72005133, committed 2015-08-05
- Comitter:
- dheerajmpai23
- Date:
- Wed Aug 05 11:19:48 2015 +0000
- Commit message:
- SPORT MODE ADF7023 WITH EXPLANATION
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 77ff72005133 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Aug 05 11:19:48 2015 +0000 @@ -0,0 +1,239 @@ +#include "mbed.h" //mbed Library +#include <iostream> +using namespace std; +#include <bitset> + +#define ENDL "\r" << endl; +#define START_ADDRESS 0x020; + +//SPI + +SPI adf(PTD6, PTD7, PTD5); //SPI Pin names in mbed + //MOSI, MISO, CLOCK + +DigitalOut CS(D10); //CS = chip select or slave select +Serial PC(USBTX, USBRX); //Serial Connection to PC Through USB port +DigitalOut ledr(LED_RED); //Blinking of LED for confirming the compilation of code + +DigitalIn clk(D8); //DigitalIn is used to poll the value of the clock +DigitalOut DT(D9); //Declaration of the pin + +int j=0; //Variable counting the bytes transmitted + +#define SPI_NOP 0xFF + +//Data that is to be transmitted +unsigned char data_TX [] = {0x65,0xD3,0x06,0x08,0xBB,0xE7,0xCD,0x16,0x65,0xD3,0x06,0x08,0xBB,0xE7,0xCD,0x16,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0xEB,0x3D,0x35,0x66,0xDC,0xDA,0x33,0xA1,0x80,0x62,0xB7,0xB8,0x88,0x8A,0xCE,0x99,0x18,0xFA,0x24,0x42,0xD1,0x7C,0x2D,0x0E,0x72,0x9E,0xE9,0x7C,0xF9,0xBA,0x18,0xAA,0x4B,0xEC,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0xCC,0xB3,0xB2,0x5B,0x96,0x38,0x71,0x96,0x54,0xE2,0x4A,0x7F,0xC9,0xB7,0x1E,0x56,0x09,0x30,0x18,0x5A,0x84,0xFA,0xC1,0x9D,0xA6,0x6A,0x17,0x50,0x6F,0xD4,0x34,0x1D,0xF0,0xE0,0xE2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x78,0xC9,0x9A,0x09,0xE2,0x34,0xF9,0x39,0x61,0x36,0x9C,0xC2,0x98,0xB9,0x54,0xC0,0xDC,0xE6,0x90,0xF6,0xF6,0x88,0xD1,0xA5,0x5A,0x75,0x83,0x78,0x08,0xD6,0x9D,0xDE,0xB8,0x58,0xD4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x13,0x3F,0x78,0xD9,0x4E,0xB7,0xE8,0xD6,0x0D,0x1E,0xF1,0xC4,0xB9,0xAB,0x90,0x39,0x6A,0x9E,0x8A,0xB8,0xC9,0xAF,0x5E,0x85,0x66,0xBF,0x4E,0xB3,0xD3,0x54,0x9B,0x7D,0xA3,0x3A,0x1A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x20,0xE5,0xEE,0x00,0x81,0x83,0x7B,0x88,0x8A,0xAB,0x31,0x91,0x8F,0xA0,0x91,0x05,0x17,0xC2,0xD2,0xB9,0xC1,0xEE,0x97,0xCE,0x66,0xE9,0x8A,0xA4,0xBC,0xB1,0xFC,0xCB,0x3B,0x24,0x6E,0x5B,0x87,0x19,0x64,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x59,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x59,0x97,0x4C,0x18,0x22,0xEF,0x9F,0x34,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + +//Note : A delay of 2 microseconds is given to ensure ADF7023 detects the CS = 'High' state and execute the command given. +//wait_us(2); ensures delay of 2 microseconds + + + +void send_data() + { + + + static int current_bit = 7; + + DT = (data_TX[j] >> current_bit) & 1; //if current bit == 1 then DT = High else DT = Low + --current_bit; //Next Bit + + if(current_bit == -1){ //If all 8 bits are transmitted. then go to next byte + current_bit = 7; //Going to the bit [0] + j++; + + + if(j>=sizeof(data_TX)) + { +// j=0; // In case repeatation of data is required + adf.write(0xB1); // Stops transmitting and reaches PHY_ON State (when repeatation is not required) + } + } +} + + + + +//BBRAM Sequence +// + +void write_bbram_sequence(void){ + + adf.write(0x19); //SPI_MEM_WR SPI Block Write BBRAM + adf.write(0x00); //Starting Address (0x100) + adf.write(0x00); //Data on 0x100 -- Interrupt_Mask Register -- As no Interrupt is required Value == 0x00 + adf.write(0x00); //Interrupt_Mask_1 No interrupts Required + + adf.write(0x00); // For details of other registers Please refer page 90-100 in ADF7023 Datasheet + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + + adf.write(0x00); + adf.write(0x33); + adf.write(0x00); + adf.write(0xF9); //BBRAm Register Corresponding to the frequency + + adf.write(0xC2); + adf.write(0x10); + adf.write(0xC0); + adf.write(0x00); + + adf.write(0x30); + adf.write(0x31); + adf.write(0x07); + adf.write(0x00); + + adf.write(0x01); + adf.write(0x00); + adf.write(0x7F); + adf.write(0x00); + + adf.write(0x0B); + adf.write(0x37); + adf.write(0x00); + adf.write(0x00); + adf.write(0x40); + adf.write(0x0C); + adf.write(0x00); + adf.write(0x05); + adf.write(0x00); + adf.write(0x00); + adf.write(0x18); + adf.write(0x12); + adf.write(0x34); + adf.write(0x56); + adf.write(0x10); + adf.write(0x10); + adf.write(0x08); + adf.write(0x14); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x04); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + adf.write(0x00); + + } + + void initiate(void){ + + CS=0; //ADF023 and mbed SPI is active low and ADF7023 samples at rising edge mode = 0; + adf.write(0x1B); + adf.write(0xFA); + adf.write(0xA0); + CS=1; // SPI goes to High impedence State + wait_us(2); + + CS=0; //Chip Select = low implies Chip is selected SPI is enabled + adf.write(0x18); + adf.write(0x0D); + adf.write(0x00); + CS=1; //Chip select == high . Chip goes to High impedence state + wait_us(2); + +// ADF7023 is now configured to SPORT MODE + + CS=0; + adf.write(0xB0); //In order to write BBRAM Sequence we need to change the state to PHY_OFF state + CS=1; + wait_us(600); + + CS=0; + write_bbram_sequence(); //BBRAM_SEQUENCE Contains all data that is required to configure the Radio + CS=1; + wait_us(2); + + CS=0; + adf.write(0xFF); //0xFF is the Dummy Byte Provides required time for ADF to get ready to accept command + adf.write(0xFF); + CS=1; + wait_us(2); + + CS=0; + adf.write(0xFF); + adf.write(0xFF); + CS=1; + wait_us(2); + + + CS=0; + adf.write(0xBB);// CONFIGURE_DEV Configures the radio according to the bbram Sequence Except the transmission frequency + CS=1; + wait_us(2); // Approx time required for state transition + + CS=0; + adf.write(0xB1);//PHY_ON Turns on the radio + CS=1; + wait_us(2); + + CS=0; + adf.write(0xB5);//PHY_TX Sets Transmission Frequency according to bbram and starts transmitting + CS=1; + wait_us(600); //Maximum time required for ADF7023 for the above State transmission . Tested in Space Lab condition + } + + + + +int main(){ + + + CS = 1; // Chip Select == low Enabling the SPI + adf.format(8,0); // SPI interfaces in 8 bit pattern ,SPI Mode = 0 + adf.frequency( 1000000 ); // SPI Frequency = 1 MHz + + cout << "Press s" << ENDL; // The following code upto 6 lines are used to ensure the data is transmitted at the required time + ledr = 1; + char c = 'a'; //Initialising the variable + + while( c != 's'){ + c = PC.getc(); + PC.putc(c); + } + ledr = 0; + + initiate(); // Initiates the Radio to Sport Mode and starts transmitting + + int state; // The datarate in which we are testing is half the Clockrate + // We are using the variable 'state' to ensure the data is sampled in alternative rising edge + + if(clk == 0){ // Initialising the State of the clock + state = 0; + } + else{ + state = 1; + } + + while(true){ // Polling + if(clk == 0){ + if(state == 1){ + state = 0; + send_data(); + } + } + else{ //As data is sampled in alternating rising edge in ADF7023 this ensures that the Data changes accordingly + state = 1; + } + } +} \ No newline at end of file
diff -r 000000000000 -r 77ff72005133 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Aug 05 11:19:48 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81 \ No newline at end of file