4-10-2015 BAE_RTOS_TEST ACS_DATA_ACQ and I2C working
Fork of BAE_RTOS_TEST1 by
Revision 1:b8c71afbe6e5, committed 2015-10-04
- Comitter:
- gkumar
- Date:
- Sun Oct 04 07:06:22 2015 +0000
- Parent:
- 0:f417d854dc29
- Commit message:
- 4-10-2015 BAE_RTOS_TEST1
Changed in this revision
diff -r f417d854dc29 -r b8c71afbe6e5 ACS.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ACS.cpp Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,133 @@ +#include "ACS.h" +#include "pin_config.h" +//....................................ATS......................................................// + +I2C i2c (PIN85,PIN84); //PTC2-sda,PTC1-scl + +Timeout g_to; //Timeout variable to +int g_toflag; +char g_cmd[2]; +float g_gyro_error[3]= {0,0,0}, g_mag_error[3]= {0,0,0}; + +/*------------------------------------------------------------------------------------------------------------------------------------------------------ +------------------------------------------- ATS data acquisition------------------------------------------------------------------------------------------*/ +void FCTN_T_OUT() +{ + g_toflag=0; //as T_OUT function gets called the while loop gets terminated +} + +void FCTN_ACS_INIT() +{ + char store; + g_cmd[0]=RESETREQ; + g_cmd[1]=BIT_RESREQ; + i2c.write(SLAVE_ADDR,g_cmd,2); //When 0x01 is written in reset request register Emulates a hard power down/power up + wait_ms(2000); //waiting for loading configuration file stored in EEPROM + g_cmd[0]=SENTRALSTATUS; + i2c.write(SLAVE_ADDR,g_cmd,1); + i2c.read(SLAVE_ADDR_READ,&store,1); + wait_ms(100); + //to check whether EEPROM is uploaded + switch((int)store) { + case(3): { + break; + } + case(11): { + break; + } + default: { + g_cmd[0]=RESETREQ; + g_cmd[1]=BIT_RESREQ; + i2c.write(SLAVE_ADDR,g_cmd,2); + wait_ms(2000); + } + } + //pc.printf("Sentral Status is %x\n",(int)store); + g_cmd[0]=HOST_CTRL; //0x01 is written in HOST CONTROL register to enable the sensors + g_cmd[1]=BIT_RUN_ENB; + i2c.write(SLAVE_ADDR,g_cmd,2); + wait_ms(100); + g_cmd[0]=MAGRATE; //Output data rate of 100Hz is used for magnetometer + g_cmd[1]=BIT_MAGODR; + i2c.write(SLAVE_ADDR,g_cmd,2); + wait_ms(100); + g_cmd[0]=GYRORATE; //Output data rate of 150Hz is used for gyroscope + g_cmd[1]=BIT_GYROODR; + i2c.write(SLAVE_ADDR,g_cmd,2); + wait_ms(100); + g_cmd[0]=ALGO_CTRL; //When 0x00 is written to ALGO CONTROL register we get scaled sensor values + g_cmd[1]=0x00; + i2c.write(SLAVE_ADDR,g_cmd,2); + wait_ms(100); + g_cmd[0]=ENB_EVT; //enabling the error,gyro values and magnetometer values + g_cmd[1]=BIT_EVT_ENB; + i2c.write(SLAVE_ADDR,g_cmd,2); + wait_ms(100); +} + +void FCTN_ATS_DATA_ACQ(float g_gyro_data[3],float g_mag_data[3]) +{ + char status; + g_toflag=1; //toFlag is set to 1 so that it enters while loop + g_to.attach(&FCTN_T_OUT,2); //after 2 seconds the while loop gets terminated + + g_cmd[0]=EVT_STATUS; + i2c.write(SLAVE_ADDR,g_cmd,1); + i2c.read(SLAVE_ADDR_READ,&status,1); + wait_ms(100); + //pc.printf("\nEvent Status is %x\n",(int)status); + //if the 6th and 4th bit are 1 then it implies that gyro and magnetometer values are ready to take + if(((int)status&40)==40) + { + FCTN_GET_DATA(g_gyro_data,g_mag_data); + printf("\n\r data received \n"); + for(int i=0; i<3; i++) + { + printf("%f\t",g_gyro_data[i]); + } + for(int i=0; i<3; i++) + { + printf("%f\t",g_mag_data[i]); + } + } + //checking for the error + else if (((int)status&2)==2) + { + FCTN_ACS_INIT(); //when there is any error then Again inilization is done to remove error + } + +} + +void FCTN_GET_DATA(float g_gyro_data[3],float g_mag_data[3]) +{ + char raw_gyro[6]; + char raw_mag[6]; + int16_t bit_data; + + float senstivity_gyro =6.5536; //senstivity is obtained from 2^15/5000dps + float senstivity_mag =32.768; //senstivity is obtained from 2^15/1000microtesla + g_cmd[0]=GYRO_XOUT_H; //0x22 gyro LSB of x + i2c.write(SLAVE_ADDR,g_cmd,1); + i2c.read(SLAVE_ADDR_READ,raw_gyro,6); + g_cmd[0]=MAG_XOUT_H; //LSB of x + i2c.write(SLAVE_ADDR,g_cmd,1); + i2c.read(SLAVE_ADDR_READ,raw_mag,6); + //pc.printf("\nGyro Values:\n"); + for(int i=0; i<3; i++) { + //concatenating gyro LSB and MSB to get 16 bit signed data values + bit_data= ((int16_t)raw_gyro[2*i+1]<<8)|(int16_t)raw_gyro[2*i]; + g_gyro_data[i]=(float)bit_data; + g_gyro_data[i]=g_gyro_data[i]/senstivity_gyro; + g_gyro_data[i]+=g_gyro_error[i]; + //pc.printf("%f\t",gyro_data[i]); + } + for(int i=0; i<3; i++) { + //concatenating mag LSB and MSB to get 16 bit signed data values + bit_data= ((int16_t)raw_mag[2*i+1]<<8)|(int16_t)raw_mag[2*i]; + g_mag_data[i]=(float)bit_data; + g_mag_data[i]=g_mag_data[i]/senstivity_mag; + g_mag_data[i]+=g_mag_error[i]; + //pc.printf("%f\t",mag_data[i]); + } + +}
diff -r f417d854dc29 -r b8c71afbe6e5 ACS.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ACS.h Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" +#include "math.h" +#include "pni.h" + +//........................................... +#define TIME_PERIOD 0.02 +#define TR_CONSTANT 0.3 + +void FCTN_ACS_GENPWM_MAIN(float*); +void FCTN_ACS_CNTRLALGO(float*,float*,float*); +void inverse(float mat[3][3],float inv[3][3]); + +void FCTN_ATS_SWITCH(bool); +void FCTN_ACS_INIT(); //initialization of registers happens +void FCTN_ATS_DATA_ACQ(float*,float*); // main function: checks errors, gets data, switches on/off the sensor +void FCTN_GET_DATA(float*,float*); //data is obtained +void FCTN_T_OUT(); //timeout function to stop infinite loop + +
diff -r f417d854dc29 -r b8c71afbe6e5 HK.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HK.cpp Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,193 @@ +#include "HK.h" +#include "pin_config.h" + + +//GPIO pins used=> D2-D12, A0-A1 + +DigitalOut SelectLinesA[]={PIN43,PIN44,PIN45,PIN46}; //to mux1=>voltage mux , PTA 13-16 , CHNGE TO PIN43 LATER +DigitalOut SelectLinesB[]={PIN56,PIN57,PIN58,PIN59}; //to mux2=>current mux(differential mux) , PTB 3,7,8,9 +//DigitalOut SelectLinesC[]={PIN64,PIN65,PIN66,PIN67}; //to mux3=>temp mux PTB 18-21 +//DigitalOut SelectLinesC[]={PIN67,PIN66,PIN65,PIN64}; +//--------------------------------------------MSB is SelectLines[0],LSB is SelectLines[3]-------------------------------- + +AnalogIn CurrentInput(PIN54); // output from Current Mux PTB0 +AnalogIn VoltageInput(PIN53); // output from Voltage Multiplexer PTB1 +AnalogIn TemperatureInput(PIN55); /*PTB2 output from Temperature Multiplexer,thermistor Multiplexer- same multiplexer for both(lines 1-4 for thermistor,line 0 for temperature sensor)*/ + + + +int quantiz(float start,float step,float x) // accepts min and measured values and step->quantises on a scale 0-15..(4 bit quantisation) +{ + int y=(x-start)/step; + if(y<=0)y=0; + if(y>=15)y=15; + return y; +} + +void init_beacon(ShortBeacy* x,SensorDataQuantised y) +{ + (*x).Voltage[0]=2; //quantised value + (*x).Temp[0]=y.PanelTemperature[0]; //quantised value + (*x).Temp[1]=y.PanelTemperature[1]; //quantised value + (*x).AngularSpeed[0]=y.AngularSpeed[0]; + (*x).AngularSpeed[1]=y.AngularSpeed[1]; + + (*x).SubsystemStatus[0]=145; //dummy values----------to be changed------------------- + (*x).ErrorFlag[0]=3; //dummy values----------to be changed------------------- +} + +SensorData Sensor; +SensorDataQuantised SensorQuantised; +ShortBeacy Shortbeacon; +void FCTN_HK_MAIN() +{ + printf("\n\r vol here %f \n",VoltageInput.read()*3.3); + //define structure variables + + //initialise all selectlines to zeroes->1st line of muxes selected + SelectLinesA[0]=SelectLinesA[1]=SelectLinesA[2]=SelectLinesA[3]=0; + SelectLinesB[0]=SelectLinesB[1]=SelectLinesB[2]=SelectLinesB[3]=0; + //SelectLinesC[0]=SelectLinesC[1]=SelectLinesC[2]=SelectLinesC[3]=0; + + int LoopIterator; + int SelectLineIterator; + + float resistance_thermistor,voltage_thermistor;//for thermistor + + //measurement from voltage sensor=> 16 sensors in place + for(LoopIterator=0; LoopIterator<16; LoopIterator++) + { + //read the sensor values and stores them in 'SensorData' structure's variable 'Sensor' + Sensor.Voltage[LoopIterator]=(VoltageInput.read()*3.3*5.545454);//resistors in voltage divider=>15Mohm,3.3Mohm + + if(LoopIterator%2==0) + SensorQuantised.Voltage[LoopIterator/2]=quantiz(vstart,vstep,Sensor.Voltage[LoopIterator]); + + else + SensorQuantised.Voltage[(LoopIterator)/2]=SensorQuantised.Voltage[(LoopIterator)/2]<<4+quantiz(vstart,vstep,Sensor.Voltage[LoopIterator]); + + //iterate the select lines from 0 to 15 + for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--) + { + if(SelectLinesA[SelectLineIterator]==0) + { + SelectLinesA[SelectLineIterator]=1; + break; + } + else SelectLinesA[SelectLineIterator]=0; + } + + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + } + + + //measurement from current sensor=> 8 sensors in place + for(LoopIterator=0; LoopIterator<8; LoopIterator++) + { + //read the sensor values and stores them in 'SensorData' structure variable 'Sensor' + Sensor.Current[LoopIterator]=(CurrentInput.read()*3.3/(50*rsens)); + if(LoopIterator%2==0) + SensorQuantised.Current[LoopIterator/2]=quantiz(cstart,cstep,Sensor.Current[LoopIterator]); + else + SensorQuantised.Current[(LoopIterator)/2]=SensorQuantised.Current[(LoopIterator)/2]<<4+quantiz(cstart,cstep,Sensor.Current[LoopIterator]); + + //iterate the select lines from 0 to 7 + for(SelectLineIterator=2;SelectLineIterator>=0;SelectLineIterator--) + { + if(SelectLinesB[SelectLineIterator]==0) + { + SelectLinesB[SelectLineIterator]=1; + break; + } + else SelectLinesB[SelectLineIterator]=0; + + } + + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + } + + + //measurement of temperature + //temperature measurement=> 4 thermistors, 1 temperature sensor + //mux line 1=>temp sensor, mux lines 2 to 5 =>thermistors + + for(LoopIterator=0; LoopIterator<5; LoopIterator++) + { + //read the sensor values and stores them in 'SensorData' structure variable 'Sensor' + Sensor.Temperature[LoopIterator]=(-90.7*3.3*TemperatureInput.read()+190.1543); + voltage_thermistor=TemperatureInput.read()*3.3;//voltage across thermistor + resistance_thermistor=24000*voltage_thermistor/(3.3-voltage_thermistor);//resistance of thermistor + if (LoopIterator==0) + { + // printf(" \n\rTemp =%f",-90.7*3.3*TemperatureInput.read()+190.1543); + } + + if(LoopIterator%2==0) + { + if(LoopIterator<1) //->corresponding to temperature sensor + SensorQuantised.Temperature[(LoopIterator)/2]=quantiz(tstart,tstep,Sensor.Temperature[LoopIterator]); + + else //->corresponding to thermistor + { + if(voltage_thermistor<1.378) //Temperature>12 degC + Sensor.PanelTemperature[(LoopIterator-1)]=(3694/log(24.032242*resistance_thermistor)); + + else + Sensor.PanelTemperature[(LoopIterator-1)]=(3365.4792/log(7.60404*resistance_thermistor)); + + + SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=quantiz(tstart_thermistor,tstep_thermistor,Sensor.PanelTemperature[(LoopIterator-1)]); + + } + } + else + { + if(LoopIterator<1) + SensorQuantised.Temperature[(LoopIterator)/2]=SensorQuantised.Temperature[(LoopIterator)/2]<<4+quantiz(tstart,tstep,Sensor.Temperature[LoopIterator]); + + else + { + if(voltage_thermistor<1.378) //Temperature>12 degC + Sensor.PanelTemperature[LoopIterator-1]=(3694/log(24.032242*resistance_thermistor)); + else + Sensor.PanelTemperature[LoopIterator-1]=(3365.4792/log(7.60404*resistance_thermistor)); + + SensorQuantised.PanelTemperature[(LoopIterator-1)/2]=SensorQuantised.PanelTemperature[(LoopIterator-1)/2]<<4+quantiz(tstart_thermistor,tstep_thermistor,Sensor.PanelTemperature[LoopIterator-1]); + } + } + // The following lines are used to iterate the select lines from 0 to 4 + //for(SelectLineIterator=3;SelectLineIterator>=0;SelectLineIterator--) +// { +// if(SelectLinesC[SelectLineIterator]==0) +// { +// SelectLinesC[SelectLineIterator]=1; +// break; +// } +// else SelectLinesC[SelectLineIterator]=0; +// } + + + + wait_us(10.0); // A delay of 10 microseconds between each sensor output. Can be changed. + +} + printf(" \n\rvol %f Temp =%f",3.3*TemperatureInput.read(),-90.7*3.3*TemperatureInput.read()+190.1543); + //update magnetometer data-> + //populate values in structure variable 'Sensor' from data to be given by Green + SensorQuantised.AngularSpeed[0]=quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[1]); + SensorQuantised.AngularSpeed[0]=SensorQuantised.AngularSpeed[0]<<4+quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[0]); + SensorQuantised.AngularSpeed[1]=quantiz(AngularSpeed_start,AngularSpeed_step,Sensor.AngularSpeed[2]); + + //update gyro data-> + //populate values in structure variable 'Sensor' from data to be given by Green + SensorQuantised.Bnewvalue[0]=quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[1]); + SensorQuantised.Bnewvalue[0]=SensorQuantised.Bnewvalue[0]<<4+quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[0]); + SensorQuantised.Bnewvalue[1]=quantiz(Bnewvalue_start,Bnewvalue_step,Sensor.Bnewvalue[2]); + + //update beacon structure + init_beacon(&Shortbeacon,SensorQuantised);//Shortbeacon is passed + printf("\n here temperature :%d",SensorQuantised.Temperature); +} + + +
diff -r f417d854dc29 -r b8c71afbe6e5 HK.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HK.h Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,69 @@ +//to be saved as HK.h + +#include "mbed.h" +#define tstart -40 +#define tstep 8 +#define tstep_thermistor 8//verify!! +#define tstart_thermistor -40 +#define vstart 3.3 +#define vstep 0.84667 +#define cstart 0.0691 +#define cstep 0.09133 +#define rsens 0.095 +#define Bnewvalue_start -100//in microTesla...max possible field is .0001 T +#define Bnewvalue_step 13.333 +#define AngularSpeed_start -10//max possible ang. velocity in space is 10 deg/sec +#define AngularSpeed_step 1.3333 + + + +typedef struct SensorData +{ + float Voltage[16]; + float Current[8]; + float Temperature[1]; + float PanelTemperature[4]; + float BatteryTemperature; //to be populated + char faultpoll; //polled faults + char faultir; //interrupted faults + char power_mode; //power modes + + float AngularSpeed[3]; //in order x,y,z + float Bnewvalue[3]; //in order Bx,By,Bz + + +} SensorData; + + +typedef struct SensorDataQuantised { + char Voltage[8]; + char Current[4]; + char Temperature[1]; + char PanelTemperature[2];//read by the 4 thermistors on solar panels + char BatteryTemperature; //to be populated + char faultpoll; //polled faults + char faultir; //interrupted faults + char power_mode; //power modes + char AngularSpeed[2]; + char Bnewvalue[2]; + + //float magnetometer,gyro=>to be addes +} SensorDataQuantised; + + +typedef struct ShortBeacon +{ + char Voltage[1]; //battery voltage from gauge, needs to be quantised + char AngularSpeed[2]; //all the 3 data + char SubsystemStatus[1]; //power modes + char Temp[2]; //temp of solar panel + //Temp[0]'s LSB=> PanelTemperature[0], Temp[0]'s MSB=> PanelTemperature[1], Temp[1]'s LSB=> PanelTemperature[2], Temp[1]'s MSB=> PanelTemperature[3] + char ErrorFlag[1]; //fault +}ShortBeacy; + + + +void FCTN_HK_MAIN(); + +int quantiz(float start,float step,float x); +void init_beacon(ShortBeacy* x,SensorDataQuantised y);
diff -r f417d854dc29 -r b8c71afbe6e5 beacon.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beacon.cpp Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,238 @@ +//switch off the sync!!!!!!! +//switch off the preamble!!!!!!! +/*for crc in tx: +regIrq2(0x28) : + +regpacketconfig 1(0x37) : +set crc detection/calc. on : | 0x10 +crcautoclearoff : | 0x08 + +for data whitening : regpacketconfig 1(0x37) :| 0x40 +for + + + +*/ +// 6CC000 for 435 MHz +//set all values as FF for checking on spectrum analyzer +#include "beacon.h" +#include "HK.h" +#include "pin_config.h" +Serial chavan(USBTX, USBRX); // tx, rx +//SPI spi(PIN2,PIN1,PIN3); // mosi, miso, sclk +DigitalOut cs(PIN14); //slave select or chip select +//SPI spi(PTD6,PTD7,PTD5); // mosi, miso, sclk +SPI spi(PIN16,PIN17,PIN15); +//DigitalOut cs_bar(PTC11); //slave select or chip select +//InterruptIn button(p9); +//#define TIMES 16 +//Timer t; + +/*void interrupt_func() +{ + chavan.printf("INTERRUPT_FUNC TRIGGERED\n wait for 3 secs\n"); + wait(3); + +}*/ + + + +extern ShortBeacy Shortbeacon; + +void writereg(uint8_t reg,uint8_t val) +{ + cs = 0;__disable_irq();spi.write(reg | 0x80);spi.write(val);__enable_irq();cs = 1; +} +uint8_t readreg(uint8_t reg) +{ + int val;cs = 0;__disable_irq();spi.write(reg & ~0x80);val = spi.write(0);__enable_irq();cs = 1;return val; +} +void clearTxBuf() +{ + writereg(RF22_REG_08_OPERATING_MODE2,0x01); + writereg(RF22_REG_08_OPERATING_MODE2,0x00); +} +void clearRxBuf() +{ + writereg(RF22_REG_08_OPERATING_MODE2,0x02); + writereg(RF22_REG_08_OPERATING_MODE2,0x00); +} +int setFrequency(float centre,float afcPullInRange) +{ +//freq setting begins + uint8_t fbsel = 0x40; + uint8_t afclimiter; + if (centre >= 480.0) { + centre /= 2; + fbsel |= 0x20; + afclimiter = afcPullInRange * 1000000.0 / 1250.0; + } else { + if (afcPullInRange < 0.0 || afcPullInRange > 0.159375) + return false; + afclimiter = afcPullInRange * 1000000.0 / 625.0; + } + centre /= 10.0; + float integerPart = floor(centre); + float fractionalPart = centre - integerPart; + + uint8_t fb = (uint8_t)integerPart - 24; // Range 0 to 23 + fbsel |= fb; + uint16_t fc = fractionalPart * 64000; + writereg(RF22_REG_73_FREQUENCY_OFFSET1, 0); // REVISIT + writereg(RF22_REG_74_FREQUENCY_OFFSET2, 0); + writereg(RF22_REG_75_FREQUENCY_BAND_SELECT, fbsel); + writereg(RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1, fc >> 8); + writereg(RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0, fc & 0xff); + writereg(RF22_REG_2A_AFC_LIMITER, afclimiter); + return 0; +} + + + +void FCTN_BEA_INIT() +{ + //reset() + writereg(RF22_REG_07_OPERATING_MODE1,0x80); //sw_reset + wait(1); //takes time to reset + + clearTxBuf(); + clearRxBuf(); + //txfifoalmostempty + writereg(RF22_REG_7D_TX_FIFO_CONTROL2,5); + //rxfifoalmostfull + writereg(RF22_REG_7E_RX_FIFO_CONTROL,20); + //Packet-engine registers + writereg(RF22_REG_30_DATA_ACCESS_CONTROL,0x8E); //RF22_REG_30_DATA_ACCESS_CONTROL, RF22_ENPACRX | RF22_ENPACTX | RF22_ENCRC | RF22_CRC_CRC_16_IBM + //&0x77 = diasable packet rx-tx handling + writereg(RF22_REG_32_HEADER_CONTROL1,0x88); //RF22_REG_32_HEADER_CONTROL1, RF22_BCEN_HEADER3 | RF22_HDCH_HEADER3 + writereg(RF22_REG_33_HEADER_CONTROL2,0x42); //RF22_REG_33_HEADER_CONTROL2, RF22_HDLEN_4 | RF22_SYNCLEN_2 + writereg(RF22_REG_34_PREAMBLE_LENGTH,8); //RF22_REG_34_PREAMBLE_LENGTH, nibbles); preamble length = 8; + writereg(RF22_REG_36_SYNC_WORD3,0x2D); //syncword3=2D + writereg(RF22_REG_37_SYNC_WORD2,0xD4); //syncword2=D4 + writereg(RF22_REG_3F_CHECK_HEADER3,0); //RF22_REG_3F_CHECK_HEADER3, RF22_DEFAULT_NODE_ADDRESS + writereg(RF22_REG_3A_TRANSMIT_HEADER3,0xab); //header_to + writereg(RF22_REG_3B_TRANSMIT_HEADER2,0xbc); //header_from + writereg(RF22_REG_3C_TRANSMIT_HEADER1,0xcd); //header_ids + writereg(RF22_REG_3D_TRANSMIT_HEADER0,0xde); //header_flags + writereg(RF22_REG_3F_CHECK_HEADER3,0xab); + writereg(RF22_REG_40_CHECK_HEADER2,0xbc); + writereg(RF22_REG_41_CHECK_HEADER1,0xcd); + writereg(RF22_REG_42_CHECK_HEADER0,0xde); + + //RSSI threshold for clear channel indicator + writereg(RF22_REG_27_RSSI_THRESHOLD,0xA5); //55 for -80dBm, 2D for -100dBm, 7D for -60dBm, A5 for -40dBm, CD for -20 dBm + + writereg(RF22_REG_0B_GPIO_CONFIGURATION0,0x15); // TX state ?? + writereg(RF22_REG_0C_GPIO_CONFIGURATION1,0x12); // RX state ?? + + //interrupts + // spiWrite(RF22_REG_05_INTERRUPT_ENABLE1, RF22_ENTXFFAEM |RF22_ENRXFFAFULL | RF22_ENPKSENT |RF22_ENPKVALID| RF22_ENCRCERROR); + // spiWrite(RF22_REG_06_INTERRUPT_ENABLE2, RF22_ENPREAVAL); + + setFrequency(435.0, 0.05); + + //return !(statusRead() & RF22_FREQERR); + if((readreg(RF22_REG_02_DEVICE_STATUS)& 0x08)!= 0x00) + printf("frequency not set properly\n"); + //frequency set + + //setModemConfig(FSK_Rb2_4Fd36); FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz + //setmodemregisters + //0x1b, 0x03, 0x41, 0x60, 0x27, 0x52, 0x00, 0x07, 0x40, 0x0a, 0x1e, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x22, 0x3a = FSK_RB2_4FD36 + //0xc8, 0x03, 0x39, 0x20, 0x68, 0xdc, 0x00, 0x6b, 0x2a, 0x08, 0x2a, 0x80, 0x60, 0x13, 0xa9, 0x2c, 0x21, 0x08 = OOK,2.4, 335 + writereg(RF22_REG_1C_IF_FILTER_BANDWIDTH,0x2B); + writereg(RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE,0x03); + writereg(RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE,0x41); + writereg(RF22_REG_21_CLOCK_RECOVERY_OFFSET2,0x60); + writereg(RF22_REG_22_CLOCK_RECOVERY_OFFSET1,0x27); //updated 20 to 25 reg values from excel sheet for 1.2 Khz freq. deviation,fsk + writereg(RF22_REG_23_CLOCK_RECOVERY_OFFSET0,0x52); + writereg(RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1,0x00); + writereg(RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0,0x51); + /*writereg(RF22_REG_2C_OOK_COUNTER_VALUE_1,0x2a); + writereg(RF22_REG_2D_OOK_COUNTER_VALUE_2,0x08);*/ //not required for fsk (OOK counter value) + writereg(RF22_REG_2E_SLICER_PEAK_HOLD,0x1e); //?? + writereg(RF22_REG_58,0x80); + writereg(RF22_REG_69_AGC_OVERRIDE1,0x60); + writereg(RF22_REG_6E_TX_DATA_RATE1,0x09); + writereg(RF22_REG_6F_TX_DATA_RATE0,0xd5); + writereg(RF22_REG_70_MODULATION_CONTROL1,0x2c); + writereg(RF22_REG_71_MODULATION_CONTROL2,0x22);//ook = 0x21 //fsk = 0x22 + writereg(RF22_REG_72_FREQUENCY_DEVIATION,0x02); + //set tx power + writereg(RF22_REG_6D_TX_POWER,0x07); //20dbm + writereg(RF22_REG_3E_PACKET_LENGTH,TX_DATA); //packet length +} + +void FCTN_BEA_MAIN() +{ + FCTN_BEA_INIT(); + printf("\n\rBeacon function entered\n\r"); + wait(1); // wait for POR to complete //change the timing later + cs=1; // chip must be deselected + wait(1); //change the time later + spi.format(8,0); + spi.frequency(10000000); //10MHz SCLK + if (readreg(RF22_REG_00_DEVICE_TYPE) == 0x08) printf("spi connection valid\n\r"); + else printf("error in spi connection\n\r"); + + + + //******** + //button.rise(&interrupt_func); //interrupt enabled ( rising edge of pin 9) + wait(0.02); // pl. update this value or even avoid it!!! + //extract values from short_beacon[] + uint8_t byte_counter = 0; + /*struct Short_beacon{ + uint8_t Voltage[1]; + uint8_t AngularSpeed[2]; + uint8_t SubsystemStatus[1]; + uint8_t Temp[3]; + uint8_t ErrorFlag[1]; + }Shortbeacon = { {0x88}, {0x99, 0xAA} , {0xAA},{0xAA,0xDD,0xEE}, {0x00} }; + */ + //filling hk data + 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]}; + + for(int i = 0; i < 15 ; i++) + { + printf("0x%X\n\r",(short_beacon[i])); + } + //tx settings begin + //setModeIdle(); + writereg(RF22_REG_07_OPERATING_MODE1,0x01); //ready mode + //fillTxBuf(data, len); + clearTxBuf(); + + //Set to Tx mode + writereg(RF22_REG_07_OPERATING_MODE1,0x09); + + while(byte_counter!=15){ + //Check for fifoThresh + while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x20) != 0x20); + //writing again + cs = 0; + spi.write(0xFF); + for(int i=7; i>=0 ;i--) + { + //pc.printf("%d\n",byte_counter); + if((short_beacon[byte_counter] & (uint8_t) pow(2.0,i))!=0) + { + spi.write(0xFF); + spi.write(0xFF); + } + else + { + spi.write(0x00); + spi.write(0x00); + + } + } + cs = 1; + byte_counter++; + + } + //rf22.waitPacketSent(); + while((readreg(RF22_REG_03_INTERRUPT_STATUS1) & 0x04) != 0x04);//pc.printf(" chck pkt sent!\n"); + printf("\nBeacon function exiting\n\r"); + +} \ No newline at end of file
diff -r f417d854dc29 -r b8c71afbe6e5 beacon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beacon.h Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,108 @@ +#include "mbed.h" + + + +#define TIMES 20 +#define RX_DATA 240 //in bytes +#define TX_DATA 240 //in bytes + +void writereg(uint8_t reg,uint8_t val); +uint8_t readreg(uint8_t reg); +void clearTxBuf(); +void clearRxBuf(); +int setFrequency(float,float); +void FCTN_BEA_INIT(); +void FCTN_BEA_MAIN(); + +#define RF22_MAX_MESSAGE_LEN 255 +// These values we set for FIFO thresholds +#define RF22_TXFFAEM_THRESHOLD 4 +#define RF22_RXFFAFULL_THRESHOLD 55 + +// Register names +#define RF22_REG_00_DEVICE_TYPE 0x00 +#define RF22_REG_02_DEVICE_STATUS 0x02 +#define RF22_REG_03_INTERRUPT_STATUS1 0x03 +#define RF22_REG_04_INTERRUPT_STATUS2 0x04 +#define RF22_REG_07_OPERATING_MODE1 0x07 +#define RF22_REG_08_OPERATING_MODE2 0x08 +#define RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE 0x09 +#define RF22_REG_0B_GPIO_CONFIGURATION0 0x0b +#define RF22_REG_0C_GPIO_CONFIGURATION1 0x0c +#define RF22_REG_0D_GPIO_CONFIGURATION2 0x0d +#define RF22_REG_1C_IF_FILTER_BANDWIDTH 0x1c +#define RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE 0x1f +#define RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE 0x20 +#define RF22_REG_21_CLOCK_RECOVERY_OFFSET2 0x21 +#define RF22_REG_22_CLOCK_RECOVERY_OFFSET1 0x22 +#define RF22_REG_23_CLOCK_RECOVERY_OFFSET0 0x23 +#define RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1 0x24 +#define RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 0x25 +#define RF22_REG_26_RSSI 0x26 +#define RF22_REG_27_RSSI_THRESHOLD 0x27 +#define RF22_REG_28_ANTENNA_DIVERSITY1 0x28 +#define RF22_REG_29_ANTENNA_DIVERSITY2 0x29 +#define RF22_REG_2A_AFC_LIMITER 0x2a +#define RF22_REG_2B_AFC_CORRECTION_READ 0x2b +#define RF22_REG_2C_OOK_COUNTER_VALUE_1 0x2c +#define RF22_REG_2D_OOK_COUNTER_VALUE_2 0x2d +#define RF22_REG_2E_SLICER_PEAK_HOLD 0x2e +#define RF22_REG_30_DATA_ACCESS_CONTROL 0x30 +#define RF22_REG_31_EZMAC_STATUS 0x31 +#define RF22_REG_32_HEADER_CONTROL1 0x32 +#define RF22_REG_33_HEADER_CONTROL2 0x33 +#define RF22_REG_34_PREAMBLE_LENGTH 0x34 +#define RF22_REG_35_PREAMBLE_DETECTION_CONTROL1 0x35 +#define RF22_REG_36_SYNC_WORD3 0x36 +#define RF22_REG_37_SYNC_WORD2 0x37 +#define RF22_REG_38_SYNC_WORD1 0x38 +#define RF22_REG_39_SYNC_WORD0 0x39 +#define RF22_REG_3A_TRANSMIT_HEADER3 0x3a +#define RF22_REG_3B_TRANSMIT_HEADER2 0x3b +#define RF22_REG_3C_TRANSMIT_HEADER1 0x3c +#define RF22_REG_3D_TRANSMIT_HEADER0 0x3d +#define RF22_REG_3E_PACKET_LENGTH 0x3e +#define RF22_REG_3F_CHECK_HEADER3 0x3f +#define RF22_REG_40_CHECK_HEADER2 0x40 +#define RF22_REG_41_CHECK_HEADER1 0x41 +#define RF22_REG_42_CHECK_HEADER0 0x42 +#define RF22_REG_43_HEADER_ENABLE3 0x43 +#define RF22_REG_44_HEADER_ENABLE2 0x44 +#define RF22_REG_45_HEADER_ENABLE1 0x45 +#define RF22_REG_46_HEADER_ENABLE0 0x46 +#define RF22_REG_47_RECEIVED_HEADER3 0x47 +#define RF22_REG_48_RECEIVED_HEADER2 0x48 +#define RF22_REG_49_RECEIVED_HEADER1 0x49 +#define RF22_REG_4A_RECEIVED_HEADER0 0x4a +#define RF22_REG_4B_RECEIVED_PACKET_LENGTH 0x4b +#define RF22_REG_58 0x58 +#define RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60 +#define RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE 0x61 +#define RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL 0x62 +#define RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION 0x63 +#define RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION 0x64 +#define RF22_REG_65_LDO_CONTROL_OVERRIDE 0x65 +#define RF22_REG_66_LDO_LEVEL_SETTINGS 0x66 +#define RF22_REG_67_DELTA_SIGMA_ADC_TUNING1 0x67 +#define RF22_REG_68_DELTA_SIGMA_ADC_TUNING2 0x68 +#define RF22_REG_69_AGC_OVERRIDE1 0x69 +#define RF22_REG_6A_AGC_OVERRIDE2 0x6a +#define RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b +#define RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE 0x6c +#define RF22_REG_6D_TX_POWER 0x6d +#define RF22_REG_6E_TX_DATA_RATE1 0x6e +#define RF22_REG_6F_TX_DATA_RATE0 0x6f +#define RF22_REG_70_MODULATION_CONTROL1 0x70 +#define RF22_REG_71_MODULATION_CONTROL2 0x71 +#define RF22_REG_72_FREQUENCY_DEVIATION 0x72 +#define RF22_REG_73_FREQUENCY_OFFSET1 0x73 +#define RF22_REG_74_FREQUENCY_OFFSET2 0x74 +#define RF22_REG_75_FREQUENCY_BAND_SELECT 0x75 +#define RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1 0x76 +#define RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0 0x77 +#define RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT 0x79 +#define RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE 0x7a +#define RF22_REG_7C_TX_FIFO_CONTROL1 0x7c +#define RF22_REG_7D_TX_FIFO_CONTROL2 0x7d +#define RF22_REG_7E_RX_FIFO_CONTROL 0x7e +#define RF22_REG_7F_FIFO_ACCESS 0x7f \ No newline at end of file
diff -r f417d854dc29 -r b8c71afbe6e5 main.cpp --- a/main.cpp Sun Oct 04 03:54:09 2015 +0000 +++ b/main.cpp Sun Oct 04 07:06:22 2015 +0000 @@ -1,32 +1,115 @@ #include "mbed.h" #include "rtos.h" +#include "pin_config.h" +//#include "HK.h" +#include "ACS.h" +//#include "beacon.h" + Serial pc(USBTX, USBRX); +InterruptIn irpt_4m_mstr(PIN38); //I2c interrupt from CDMS +DigitalOut irpt_2_mstr(PIN4); //I2C interrupt to CDMS +I2CSlave slave (PIN1,PIN2); +const int addr = 0x20; //slave address +Thread *ptr_t_i2c; +Timer t; // time taken from isr to reach i2c function +Timer t1; +Timer t_exec; //To know the time of execution each thread + +Timer t_start; //To know the time of entering of each thread +Timer t_i2c_start; //To check the time sync in i2c communication +Timer t_i2c_exec; //To know the time taken by i2c read/write function Thread *ptr_t_hk; Thread *ptr_t_acs; Thread *ptr_t_bea; +/**************************************************************global variables*********************************************************************************/ +char hk_data[25]; + +/**************************************************************funtion header**********************************************************************************/ + +void FCTN_HK_DATA_CATENATE(); + + +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK : HK +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//extern SensorDataQuantised SensorQuantised; void T_HK(void const *args) { while(1){ - Thread::signal_wait(0x2); - pc.printf("HK thread here\r \n"); + Thread::signal_wait(0x2); + //SensorQuantised.power_mode='3'; //default power mode(dummy) +// printf("\n\rTHIS IS HK %f\n\r",t_start.read()); +// t_exec.start(); +// FCTN_HK_MAIN(); //Collecting HK data +// FCTN_HK_DATA_CATENATE(); //sending HK data to CDMS +// t_exec.stop(); +// //printf("The time to execute hk_acq is %f seconds\n\r",t_exec.read()); +// t_exec.reset(); + printf("\n\rTHIS IS HK %f\n\r",t_start.read()); } } +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK : ACS data +//--------------------------------------------------------------------------------------------------------------------------------------------------- + void T_ACS(void const *args){ - while(1){ - Thread::signal_wait(0x1); - pc.printf(" ACS thread here\r \n"); - } + + float mag_field1[3]; + float omega1[3]; + //float tauc1[3]; + //float moment[3]; + //float *mnm_data; + while(1) + { + Thread::signal_wait(0x1); + printf("\n\rEntered ACS %f\n",t_start.read()); + FCTN_ATS_DATA_ACQ(omega1,mag_field1); //the angular velocity is stored in the first 3 values and magnetic field values in next 3 + printf("\n\rmnm gyro values\n"); //printing the angular velocity and magnetic field values + for(int i=0; i<3; i++) + { + printf("%f\t",omega1[i]); + } + printf("\n\r mnm mag values\n"); + for(int i=0; i<3; i++) + { + printf("%f\t",mag_field1[i]); + } + t_exec.reset(); + + } } +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK : Beacon +//--------------------------------------------------------------------------------------------------------------------------------------------------- +int beac_flag=0; void T_BEA(void const *args){ while(1){ Thread::signal_wait(0x3); - pc.printf("BEA thread here\r \n"); - } + printf("\n\rTHIS IS BEACON %f\n\r",t_start.read()); +// t_exec.start(); +// FCTN_BEA_MAIN(); +// if(beac_flag==1) +// { +// Thread::wait(600000); +// beac_flag = 0; +// } +// printf("The time to execute beacon thread is %f seconds\n\r",t_exec.read()); +// t_exec.reset(); + } } + + +//extern SensorDataQuantised SensorQuantised; + + +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK : Scheduler +//--------------------------------------------------------------------------------------------------------------------------------------------------- + uint8_t schedcount=1; void T_SC(void const *args) { @@ -55,20 +138,188 @@ } schedcount++; } +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK : i2c data +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//void FCTN_I2C_READ(char *data,int length); +//void FCTN_I2C_WRITE(char *data,int length); +bool write_ack = 1; +bool read_ack = 1; +char data_send[10]; +char data_receive[10]; +char short_tc[10]; +char long_tc[134]; +char mstr_cmd = '0'; +bool cmd_flag = 1; +int length=10; + +void T_I2C_SLAVE(void const * args) +{ + while(1) + { + cmd_flag = 1; + Thread::signal_wait(0x4); + wait_us(100); // can be between 38 to 15700 + //printf("\n\r check 1\n"); + t.stop(); + if( slave.receive() == 0) + slave.stop(); + if( slave.receive() == 1) // slave writes to master + { + t1.start(); + write_ack=slave.write(data_send,length); + t1.stop(); + if(write_ack == 0) + printf("\n\rData sent to CDMS is %s \n",data_send); + slave.stop(); + } + if( slave.receive()==3 || slave.receive()==2) // slave read + { + t1.start(); + read_ack=slave.read(data_receive,length); + t1.stop(); + if(read_ack == 0) + printf("\n\r Data received from CDMS is %s \n",data_receive); + slave.stop(); + } + printf("\n \r %d %d\n",t.read_us(),t1.read_us()); + t.reset(); + t1.reset(); + } + + // if(cmd_flag == 1) +// { +// t.stop(); +// if( slave.receive()==3 || slave.receive()==2) // slave read +// { +// +// t1.start(); +// read_ack=slave.read(&mstr_cmd,1); +// t1.stop(); +// if(read_ack == 0) +// { +// printf("\n\r Data received from CDMS is %c \n",mstr_cmd); +// switch(mstr_cmd) +// { +// case 's': +// length = 11; +// cmd_flag = 0; +// break; +// +// case 'l': +// length = 135; +// cmd_flag = 0; +// break; +// +// case 'h': +// length = 25; +// cmd_flag = 0; +// FCTN_I2C_WRITE(hk_data,length ); +// break; +// +// default: +// printf("\n\r invalid command \n"); +// //cmd_err = 0; +// cmd_flag = 1; +// } +// } +// else +// cmd_flag = 1; +// } +// else +// cmd_flag = 1; +// } +// printf("\n \r %d %d\n",t.read_us(),t1.read_us()); +// t.reset(); +// t1.reset(); +// +// +// } +//} +// +//void FCTN_I2C_READ(char *data, int length ) +//{ +// t1.start(); +// read_ack=slave.read(data,length); +// t1.stop(); +// if(read_ack == 0) +// printf("\n\rData received from CDMS is %s \n",data); +// else +// printf("\n\r data not received \n"); +//} +// +//void FCTN_I2C_WRITE(char *data,int length) +//{ +// t1.start(); +// write_ack=slave.write(data,length); +// t1.stop(); +// if(write_ack == 0) +// printf("\n\rData sent to CDMS is %s \n",data); +// else +// printf("\n\r data not sent\n"); +} + + +void FCTN_ISR_I2C() +{ + ptr_t_i2c->signal_set(0x4); + t.start(); +} +//void FCTN_HK_DATA_CATENATE() +//{ +// strcpy(hk_data,"hk_Data"); +// strcat(hk_data,SensorQuantised.Voltage); +// strcat(hk_data,SensorQuantised.Current); +// strcat(hk_data,SensorQuantised.PanelTemperature); +// strcat(hk_data,SensorQuantised.AngularSpeed); +// strcat(hk_data,SensorQuantised.Bnewvalue); +// char fdata[5] = {SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir,SensorQuantised.power_mode}; +// /*strcat(hk_data,sfaultpoll); +// strcat(hk_data,sfaultir); +// strcat(hk_data,spower_mode);*/ +// strcat(hk_data,fdata); +// printf("\n\r hk data being sent is %s ",hk_data); +//} + +//----------------------------------------------------------------------------BAE_INIT------------------------------------------------------------- + +void FCTN_BAE_INIT() +{ + slave.address(0x20); // setting slave address for BAE for I2C communication + FCTN_ACS_INIT(); // Initializing mnm blue + //FCTN_BAE_HK_INIT(); + //FCTN_BEA_INIT(); +} + + +//--------------------------------------------------------------------------------------------------------------------------------------------------- +//TASK : Main +//--------------------------------------------------------------------------------------------------------------------------------------------------- + int main(){ ptr_t_hk = new Thread(T_HK); ptr_t_acs = new Thread(T_ACS); ptr_t_bea = new Thread(T_BEA); + ptr_t_i2c= new Thread(T_I2C_SLAVE); ptr_t_acs->set_priority(osPriorityAboveNormal); ptr_t_hk->set_priority(osPriorityAboveNormal); ptr_t_bea->set_priority(osPriorityAboveNormal); + ptr_t_i2c->set_priority(osPriorityRealtime); + RtosTimer t_sc_timer(T_SC,osTimerPeriodic); // Initiating the scheduler thread - t_sc_timer.start(10000); + t_sc_timer.start(10000); + printf("\n\r BAE ACTIVATED\n"); + FCTN_BAE_INIT(); + //strcpy(data_send,"sakthi"); + slave.address(addr); + irpt_4m_mstr.enable_irq(); + irpt_4m_mstr.rise(&FCTN_ISR_I2C); + while(1) //required to prevent main from terminating {
diff -r f417d854dc29 -r b8c71afbe6e5 pin_config.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pin_config.h Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,101 @@ +// 100 LQFP format pin assignment +#define PIN1 PTE0 +#define PIN2 PTE1 +#define PIN3 PTE2 +#define PIN4 PTE3 +#define PIN5 PTE4 +#define PIN6 PTE5 +#define PIN7 PTE6 +//#define 8 +//#define 9 +//#define 10 +//#define 11 +//#define 12 +//#define 13 +#define PIN14 PTE16 +#define PIN15 PTE17 +#define PIN16 PTE18 +#define PIN17 PTE19 +#define PIN18 PTE20 +#define PIN19 PTE21 +#define PIN20 PTE22 +#define PIN21 PTE23 +//#define 22 +//#define 23 +//#define 24 +//#define 25 +#define PIN26 PTE29 +#define PIN27 PTE30 +#define PIN28 PTE31 +//#define 29 +//#define 30 +#define PIN31 PTE24 +#define PIN32 PTE25 +#define PIN33 PTE26 +#define PIN34 PTA0 +#define PIN35 PTA1 +#define PIN36 PTA2 +#define PIN37 PTA3 +#define PIN38 PTA4 +#define PIN39 PTA5 +#define PIN40 PTA6 +#define PIN41 PTA7 +#define PIN42 PTA12 +#define PIN43 PTA13 +#define PIN44 PTA14 +#define PIN45 PTA15 +#define PIN46 PTA16 +#define PIN47 PTA17 +//#define 48 +//#define 49 +#define PIN50 PTA18 +#define PIN51 PTA19 +#define PIN52 PTA20 +#define PIN53 PTB0 +#define PIN54 PTB1 +#define PIN55 PTB2 +#define PIN56 PTB3 +#define PIN57 PTB7 +#define PIN58 PTB8 +#define PIN59 PTB9 +#define PIN60 PTB10 +#define PIN61 PTB11 +#define PIN62 PTB16 +#define PIN63 PTB17 +#define PIN64 PTB18 +#define PIN65 PTB19 +#define PIN66 PTB20 +#define PIN67 PTB21 +#define PIN68 PTB22 +#define PIN69 PTB23 +#define PIN70 PTC0 +#define PIN71 PTC1 +#define PIN72 PTC2 +#define PIN73 PTC3 +//#define 74 +//#define 75 +#define PIN76 PTC20 +#define PIN77 PTC21 +#define PIN78 PTC22 +#define PIN79 PTC23 +#define PIN80 PTC4 +#define PIN81 PTC5 +#define PIN82 PTC6 +#define PIN83 PTC7 +#define PIN84 PTC8 +#define PIN85 PTC9 +#define PIN86 PTC10 +#define PIN87 PTC11 +#define PIN88 PTC12 +#define PIN89 PTC13 +#define PIN90 PTC16 +#define PIN91 PTC17 +#define PIN92 PTC18 +#define PIN93 PTD0 +#define PIN94 PTD1 +#define PIN95 PTD2 +#define PIN96 PTD3 +#define PIN97 PTD4 +#define PIN98 PTD5 +#define PIN99 PTD6 +#define PIN100 PTD7 \ No newline at end of file
diff -r f417d854dc29 -r b8c71afbe6e5 pni.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pni.h Sun Oct 04 07:06:22 2015 +0000 @@ -0,0 +1,37 @@ +#define SLAVE_ADDR 0x50 +#define SLAVE_ADDR_READ 0x51 +#define SENTRALSTATUS 0x37 +#define RESETREQ 0x9B +#define MAGRATE 0x55 +#define ACCERATE 0x56 +#define GYRORATE 0x57 +#define QRATE_DIV 0x32 +#define ALGO_CTRL 0x54 +#define ENB_EVT 0x33 +#define HOST_CTRL 0x34 +#define EVT_STATUS 0x35 +#define ALGO_STATUS 0x38 +#define GYRO_XOUT_H 0x22 +#define MAG_XOUT_H 0X12 + +//Configaration bits +#define BIT_RESREQ 0x01 +#define BIT_EEP_DET 0x01 +#define BIT_EEP_UPDN 0x02 +#define BIT_EEP_UPERR 0x04 +#define BIT_EEP_IDLE 0x08 +#define BIT_EEP_NODET 0x10 +#define BIT_STBY 0x01 +#define BIT_RAW_ENB 0x02 +#define BIT_HPR_OUT 0x04 +#define BIT_CPU_RES 0x01 +#define BIT_ERR 0x02 +#define BIT_QRES 0x04 +#define BIT_MAG_RES 0x08 +#define BIT_ACC_RES 0x10 +#define BIT_GYRO_RES 0x20 +#define BIT_GYROODR 0x0F +#define BIT_MAGODR 0x64 +#define BIT_RUN_ENB 0x01 +#define BIT_ALGO_RAW 0x02 +#define BIT_EVT_ENB 0X2A \ No newline at end of file