sakthi priya amirtharaj / Mbed 2 deprecated pcb_test_v1_1_1

Dependencies:   mbed-rtos mbed

Fork of pcb_test_v1_1 by sakthi priya amirtharaj

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers beacon.cpp Source File

beacon.cpp

00001 //switch off the sync!!!!!!!
00002 //switch off the preamble!!!!!!!
00003 /*for crc in tx:
00004 regIrq2(0x28) :
00005 
00006 regpacketconfig 1(0x37) :
00007 set crc detection/calc. on : | 0x10
00008 crcautoclearoff : | 0x08  
00009 
00010 for data whitening : regpacketconfig 1(0x37) :| 0x40
00011 for 
00012 
00013 
00014 
00015 */
00016 // 6CC000 for 435 MHz
00017 //set all values as FF for checking on spectrum analyzer
00018 #include "beacon.h"
00019 #include "HK.h"
00020 #include "pin_config.h"
00021 Serial chavan(USBTX, USBRX);           // tx, rx
00022 //SPI spi(PIN2,PIN1,PIN3);               // mosi, miso, sclk
00023 DigitalOut cs_bar(PIN6);                 //slave select or chip select
00024 SPI spi(PTD6,PTD7,PTD5);               // mosi, miso, sclk
00025 //DigitalOut cs_bar(PTC11);              //slave select or chip select
00026 //InterruptIn button(p9);
00027 //#define TIMES 16      
00028 //Timer t;
00029 
00030 /*void interrupt_func()
00031 {
00032     chavan.printf("INTERRUPT_FUNC TRIGGERED\n  wait for 3 secs\n"); 
00033     wait(3);
00034     
00035 }*/
00036 
00037 extern  ShortBeacy Shortbeacon;
00038 void writereg(uint8_t reg,uint8_t val)
00039 {
00040     cs_bar = 0;
00041     spi.write(reg | 0x80);      
00042     spi.write(val);
00043     cs_bar = 1;
00044 }
00045 uint8_t readreg(uint8_t reg)
00046 {
00047     uint8_t val;
00048     cs_bar = 0;
00049     spi.write(reg & ~0x80);        
00050     val = spi.write(0);
00051     cs_bar = 1;
00052     return val;
00053 }
00054         
00055 void FUNC_BEA() {
00056     
00057     //button.rise(&interrupt_func);         //interrupt enabled ( rising edge of pin 9)
00058     printf("\n\rBeacon function entered\n\r");
00059     wait(0.02);                             //takes 10 ms for POR event + 10ms for safety                 
00060     
00061     uint8_t byte_counter = 0;
00062     
00063     /*struct Short_beacon{
00064         uint8_t Voltage[1];
00065         uint8_t AngularSpeed[2];
00066         uint8_t SubsystemStatus[1];
00067         uint8_t Temp[3];
00068         uint8_t ErrorFlag[1];
00069         }Shortbeacon = { {0x22}, {0x22, 0x33} , {0x00},{0x00,0x00,0x00}, {0xFE} };
00070     */
00071     //filling hk data
00072     //ShortBeacon Shortbeacon;
00073     uint8_t short_beacon[] = { 0xAB, 0x8A, 0xE2, 0xBB, 0xB8, 0xA2, 0x8E,Shortbeacon.Voltage[0],Shortbeacon.AngularSpeed[0], Shortbeacon.AngularSpeed[1],Shortbeacon.SubsystemStatus[0],Shortbeacon.Temp[0],Shortbeacon.Temp[1],Shortbeacon.Temp[2],Shortbeacon.ErrorFlag[0]};
00074     
00075     //mask
00076     //uint8_t mask[] = {0x80, 0x40, 0x20,0x10,0x8,0x4,0x2,0x1};
00077         
00078     for(int i = 0; i < 15 ; i++)
00079     {
00080         chavan.printf("0x%X\n\r",(short_beacon[i]));    
00081     }
00082     
00083     spi.format(8,0);                    
00084     spi.frequency(10000000);             //10MHz SCLK frequency(its max for rfm69hcw)
00085     cs_bar = 1;                              // Chip must be deselected
00086     
00087     //initialization
00088     //Common configuration registers
00089     writereg(0x01,0x04);       //sequencer on,standby mode
00090     writereg(0x02,0x08);       //packet-mode used  , ook modultion , no dc-shaping
00091     writereg(0x03,0x68);       //1200bps datarate
00092     writereg(0x04,0x2B);       //1200bps datarate
00093     writereg(0x07,0x6C);       //Frequency MSB
00094     writereg(0x08,0xC0);       //Frequency MID
00095     writereg(0x09,0x00);       //Frequency LSB        ....6C C0 00 for 435 MHZ   
00096     
00097     //Transmitter registers
00098     // RegPaLevel(default +13 dBm)
00099     
00100     //IRQ and Pin Mapping Registers
00101     //no DIO mapped yet
00102     //regirq1(0x27): modeready (8th bit) will be checked for interrupts
00103     //regIrq2(0x28): fifothresh (5th bit) ,packetsent(3rd bit) will be checked for interrupts
00104     
00105     //Packet Engine Registers
00106     writereg(0x2C,0x00);        //set preamble
00107     writereg(0x2D,0x0A);        //set preamble
00108     writereg(0x2E,0x80);        //sync off        
00109     writereg(0x2F,0x5E);        //sync word 1               
00110     writereg(0x37,0x08 | 0x40);// | 0x10);        //packetconfig1, 0x40 for data whitening (only for testing)                
00111     writereg(0x38,0x00);        //payload length = 0 ... unlimited payload mode
00112     writereg(0x3C,0xB0);         //fifothresh = 48      because we want it cleared once its 40!!!!
00113     //Initialization complete
00114     
00115     //while(chavan.getc() == 't'){
00116     //t.start();  
00117     //Filling Data into FIFO 64 BYTES : eff.32 bits = 4bytes                  //fread
00118     cs_bar = 0; 
00119     spi.write(0x80);//fifo write access
00120     for(byte_counter=0 ; byte_counter<4; byte_counter++)
00121     {    
00122         for(int i=7; i>=0  ; i--)
00123         {
00124             if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0)
00125             //if((short_beacon[byte_counter] & mask[i]) != 0)
00126             {
00127                 spi.write(0xFF);
00128                 spi.write(0xFF);
00129             }
00130     else
00131             {
00132                 spi.write(0x00);
00133                 spi.write(0x00);
00134             }
00135         }
00136     }
00137     cs_bar = 1; //cs_bar
00138                 
00139     //Check for fifoThresh
00140     printf("\n\rfor loop executed\n\r");
00141     while((readreg(0x28) & 0x20) != 0x20);                         
00142     printf("\n\rwhile loop executed\n\r");
00143     //Highpower settings
00144     writereg(0x11,0x7F);    //RegPalevel (20db)                //~
00145     writereg(0x13,0x0F);    //RegOCP
00146     writereg(0x5A,0x5D);    //RegTestPa1
00147     writereg(0x5C,0x7C);    //RegTestPa2
00148         
00149     //Set to Tx mode
00150     writereg(0x01,0x0C);
00151     
00152         printf("\n\rpre 2nd while loop\n\r");
00153         //Check for fifoThresh
00154         while((readreg(0x28) & 0x20) != 0x00);  
00155         printf("\n\r2nd while loop executed\n\r");        
00156         while(byte_counter!=15){
00157             
00158         //writing again
00159         cs_bar = 0;
00160         spi.write(0x80);   
00161         for(int i=7; i>=0 ;i--)
00162         {
00163             if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0)
00164             //if((short_beacon[byte_counter] & mask[i]) != 0)
00165         {
00166             spi.write(0xFF);
00167             spi.write(0xFF);
00168         }
00169         else
00170         {
00171             spi.write(0x00);
00172             spi.write(0x00);
00173         }
00174         }
00175         cs_bar = 1;
00176         byte_counter++;
00177                        
00178         //Check for fifoThresh
00179         while((readreg(0x28) & 0x20) != 0x00);
00180     }
00181     printf("\n\r3rd big while loop executed\n\r");
00182     //wait for packet sent bit to fire
00183     while((readreg(0x28) & 0x08) != 0x08);
00184     printf("\n\r4th while loop executed\n\r");
00185     //chavan.printf("packet sent!!! \n\r");    
00186     
00187     //Switch back to Standby Mode
00188     writereg(0x01,0x04);
00189     
00190     //Lowpowermode
00191     writereg(0x11,0x9F);    //RegPalevel (13db)
00192     writereg(0x13,0x1A);    //RegOCP
00193     writereg(0x5A,0x55);    //RegTestPa1(setting PA_BOOST on RFIO)
00194     writereg(0x5C,0x70);    //RegTestPa2(setting PA_BOOST on RFIO)
00195     
00196     //wait for modeready
00197     while((readreg(0x27)&0x80)!=0x80);
00198     
00199     //t.stop();
00200     //chavan.printf(" time taken to init + transmit = %f \n", t.read()) ;
00201     //}
00202 printf("\n\rBeacon function exiting\n\r");
00203 }