PYLD_CDMS

Dependencies:   mbed

Fork of PLYD_CDMSee by Siva ram

Committer:
Piasiv1206
Date:
Sat Oct 03 10:20:07 2015 +0000
Revision:
2:623747e75e3c
Parent:
1:72227bdac415
Child:
3:d2307fb2455c
pinnochio

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Piasiv1206 0:58ec354d3b79 1
Piasiv1206 0:58ec354d3b79 2
Piasiv1206 0:58ec354d3b79 3 // Payload uC (Tiva) -- > SPI master
Piasiv1206 0:58ec354d3b79 4 // CDMS uC (Freescale) --> SPI slave
Piasiv1206 0:58ec354d3b79 5 // packet length = 32*16 bits (32 bins --> each 2 bytes)
Piasiv1206 0:58ec354d3b79 6
Piasiv1206 0:58ec354d3b79 7 #include "mbed.h"
Piasiv1206 2:623747e75e3c 8 //int f;
Piasiv1206 0:58ec354d3b79 9 void FUNC_MASTER_WRITE(void);
Piasiv1206 0:58ec354d3b79 10 const int addr = 0x20<<1;
Piasiv1206 1:72227bdac415 11 const int addr1 = (0x20<<1|0);
Piasiv1206 0:58ec354d3b79 12 Timer Siv ;
Piasiv1206 0:58ec354d3b79 13 I2C master (D14,D15);
Piasiv1206 0:58ec354d3b79 14 InterruptIn PYLD_I2C_Int(PTA13);
Piasiv1206 2:623747e75e3c 15 //DigitalIn test(PTA13);
Piasiv1206 0:58ec354d3b79 16 SPISlave device(PTD6, PTD7, PTD5,PTD4 ); // mosi, miso, sclk, ssel --> using SPI1
Piasiv1206 0:58ec354d3b79 17 InterruptIn PYLD_SPI_Interrupt(PTD2);
Piasiv1206 2:623747e75e3c 18 DigitalOut flash(LED4);
Piasiv1206 2:623747e75e3c 19 int payloadBins = 3096;
Piasiv1206 0:58ec354d3b79 20 float Stability_delay = 0.005228 ;// 0.005228
Piasiv1206 0:58ec354d3b79 21
Piasiv1206 0:58ec354d3b79 22 Serial pc(USBTX, USBRX); // tx, rx --> serial feedback for debug
Piasiv1206 0:58ec354d3b79 23
Piasiv1206 0:58ec354d3b79 24 void payloadProcess() {
Piasiv1206 0:58ec354d3b79 25
Piasiv1206 0:58ec354d3b79 26
Piasiv1206 0:58ec354d3b79 27 //wait(Stability_delay); // wait after interrupt for stability
Piasiv1206 0:58ec354d3b79 28 unsigned short scienceRawPacket[payloadBins];
Piasiv1206 0:58ec354d3b79 29
Piasiv1206 0:58ec354d3b79 30 for(int i=0; i<payloadBins;i++){
Piasiv1206 0:58ec354d3b79 31
Piasiv1206 0:58ec354d3b79 32
Piasiv1206 0:58ec354d3b79 33
Piasiv1206 0:58ec354d3b79 34 while(!device.receive()); // blocking statement --> waiting for data from Payload
Piasiv1206 0:58ec354d3b79 35 scienceRawPacket[i] = device.read(); // Read byte from master
Piasiv1206 0:58ec354d3b79 36
Piasiv1206 0:58ec354d3b79 37 }
Piasiv1206 0:58ec354d3b79 38 // serial feedback
Piasiv1206 0:58ec354d3b79 39 pc.printf("Packet recieved\r\n");
Piasiv1206 0:58ec354d3b79 40 for(int i=0;i<payloadBins;i++){
Piasiv1206 0:58ec354d3b79 41 pc.printf("%d\t",scienceRawPacket[i]);
Piasiv1206 0:58ec354d3b79 42 scienceRawPacket[i] = 0;
Piasiv1206 0:58ec354d3b79 43 }
Piasiv1206 0:58ec354d3b79 44 pc.printf("\r\n");
Piasiv1206 0:58ec354d3b79 45
Piasiv1206 0:58ec354d3b79 46 }
Piasiv1206 0:58ec354d3b79 47 int dt3;
Piasiv1206 0:58ec354d3b79 48 bool f = 1;
Piasiv1206 2:623747e75e3c 49 char rdata[30],rdata2;
Piasiv1206 0:58ec354d3b79 50 void readds()
Piasiv1206 0:58ec354d3b79 51 {
Piasiv1206 0:58ec354d3b79 52
Piasiv1206 0:58ec354d3b79 53 //wait(Stability_delay);
Piasiv1206 2:623747e75e3c 54 flash = !flash;
Piasiv1206 2:623747e75e3c 55
Piasiv1206 0:58ec354d3b79 56
Piasiv1206 2:623747e75e3c 57
Piasiv1206 2:623747e75e3c 58 //while(!f)
Piasiv1206 2:623747e75e3c 59 //{
Piasiv1206 2:623747e75e3c 60 f= master.read(addr1,rdata,26);
Piasiv1206 2:623747e75e3c 61 //}
Piasiv1206 2:623747e75e3c 62 /*
Piasiv1206 2:623747e75e3c 63 for(int i = 0;i<10;i++)
Piasiv1206 2:623747e75e3c 64 {
Piasiv1206 2:623747e75e3c 65 master.start();
Piasiv1206 2:623747e75e3c 66 master.write(addr1);
Piasiv1206 2:623747e75e3c 67 rdata[i] = master.read(1);
Piasiv1206 2:623747e75e3c 68 master.stop();
Piasiv1206 2:623747e75e3c 69 }
Piasiv1206 2:623747e75e3c 70
Piasiv1206 2:623747e75e3c 71 master.read(addr1,&rdata[0],1);
Piasiv1206 2:623747e75e3c 72 master.read(addr1,&rdata[1],1);
Piasiv1206 2:623747e75e3c 73 master.read(addr1,&rdata[2],1);
Piasiv1206 2:623747e75e3c 74 master.read(addr1,&rdata[3],1);
Piasiv1206 2:623747e75e3c 75 master.read(addr1,&rdata[4],1);
Piasiv1206 2:623747e75e3c 76 master.read(addr1,&rdata[5],1);
Piasiv1206 2:623747e75e3c 77 master.read(addr1,&rdata[6],1);
Piasiv1206 2:623747e75e3c 78 master.read(addr1,&rdata[7],1);
Piasiv1206 2:623747e75e3c 79 master.read(addr1,&rdata[8],1);
Piasiv1206 2:623747e75e3c 80 master.read(addr1,&rdata[9],1);
Piasiv1206 2:623747e75e3c 81 master.read(addr1,&rdata[10],1);
Piasiv1206 2:623747e75e3c 82 master.read(addr1,&rdata[11],1);
Piasiv1206 2:623747e75e3c 83 master.read(addr1,&rdata[12],1);
Piasiv1206 2:623747e75e3c 84 */
Piasiv1206 0:58ec354d3b79 85 // dt3 = master.read(1);
Piasiv1206 0:58ec354d3b79 86
Piasiv1206 0:58ec354d3b79 87
Piasiv1206 0:58ec354d3b79 88 }
Piasiv1206 0:58ec354d3b79 89
Piasiv1206 0:58ec354d3b79 90 int loop=1;
Piasiv1206 0:58ec354d3b79 91 char *writedata = new char;
Piasiv1206 2:623747e75e3c 92 char data = 1,data1 = 2, data2 = 3, test[136] ;
Piasiv1206 2:623747e75e3c 93
Piasiv1206 0:58ec354d3b79 94
Piasiv1206 0:58ec354d3b79 95 void FUNC_MASTER_WRITE(void)
Piasiv1206 2:623747e75e3c 96 {
Piasiv1206 2:623747e75e3c 97
Piasiv1206 2:623747e75e3c 98 for (dt3 = 0;dt3 <11 ; dt3++)
Piasiv1206 2:623747e75e3c 99 {
Piasiv1206 2:623747e75e3c 100 test [dt3] = 1 ;
Piasiv1206 2:623747e75e3c 101 }
Piasiv1206 2:623747e75e3c 102 int data5 = pc.getc();
Piasiv1206 0:58ec354d3b79 103 loop=1;
Piasiv1206 0:58ec354d3b79 104
Piasiv1206 0:58ec354d3b79 105
Piasiv1206 0:58ec354d3b79 106 master.frequency(100000);
Piasiv1206 1:72227bdac415 107 *writedata = data1;
Piasiv1206 0:58ec354d3b79 108 while(loop)
Piasiv1206 0:58ec354d3b79 109 {
Piasiv1206 2:623747e75e3c 110
Piasiv1206 2:623747e75e3c 111 bool check = (bool)master.write(addr,test,135);
Piasiv1206 2:623747e75e3c 112
Piasiv1206 2:623747e75e3c 113 //wait_us(10);
Piasiv1206 2:623747e75e3c 114
Piasiv1206 2:623747e75e3c 115 //check = (bool)master.write(addr,&data1,1);
Piasiv1206 2:623747e75e3c 116 // check = (bool)master.write(addr,&data1,1);
Piasiv1206 2:623747e75e3c 117 //check = (bool)master.write(addr,&data2,1);
Piasiv1206 2:623747e75e3c 118 //bool check = master.write(addr,test,3);
Piasiv1206 2:623747e75e3c 119
Piasiv1206 2:623747e75e3c 120 // while(!test);
Piasiv1206 2:623747e75e3c 121
Piasiv1206 2:623747e75e3c 122 // readds();
Piasiv1206 1:72227bdac415 123
Piasiv1206 2:623747e75e3c 124 //master.start();
Piasiv1206 2:623747e75e3c 125 //bool check1 = master.write(addr1);
Piasiv1206 2:623747e75e3c 126 // wait_us(10);
Piasiv1206 2:623747e75e3c 127 // bool check2 = master.write(3);
Piasiv1206 2:623747e75e3c 128 //wait_us(10);
Piasiv1206 2:623747e75e3c 129 // check2 = master.write(1);
Piasiv1206 2:623747e75e3c 130 // master.write(97);
Piasiv1206 2:623747e75e3c 131 //master.write(107);
Piasiv1206 2:623747e75e3c 132 //master.write(116);
Piasiv1206 2:623747e75e3c 133 //master.write(104);
Piasiv1206 2:623747e75e3c 134 //master.write(105);
Piasiv1206 2:623747e75e3c 135 //wait_us(10);
Piasiv1206 2:623747e75e3c 136 //master.write(32);
Piasiv1206 2:623747e75e3c 137 //master.write(80);
Piasiv1206 2:623747e75e3c 138 //master.write(114);
Piasiv1206 2:623747e75e3c 139 //master.write(105);
Piasiv1206 2:623747e75e3c 140 //master.write(121);
Piasiv1206 2:623747e75e3c 141 //master.write(97);
Piasiv1206 2:623747e75e3c 142
Piasiv1206 2:623747e75e3c 143 // master.stop();
Piasiv1206 2:623747e75e3c 144
Piasiv1206 1:72227bdac415 145
Piasiv1206 0:58ec354d3b79 146
Piasiv1206 0:58ec354d3b79 147 loop = 0;
Piasiv1206 0:58ec354d3b79 148 }
Piasiv1206 0:58ec354d3b79 149 }
Piasiv1206 2:623747e75e3c 150
Piasiv1206 0:58ec354d3b79 151 int main() {
Piasiv1206 2:623747e75e3c 152 int dt1 = 0,dt2 = 0 ,P= 0;
Piasiv1206 0:58ec354d3b79 153 device.format(16,0); // SPI format --> 16 bits, mode = 0
Piasiv1206 0:58ec354d3b79 154 device.frequency(1000000);
Piasiv1206 2:623747e75e3c 155 // master.frequency(400000);
Piasiv1206 0:58ec354d3b79 156
Piasiv1206 0:58ec354d3b79 157 pc.printf("Example code demonstarting Payload - CDMS SPI & I2C communication!\r\n");
Piasiv1206 0:58ec354d3b79 158 PYLD_SPI_Interrupt.rise(&payloadProcess);
Piasiv1206 0:58ec354d3b79 159 PYLD_I2C_Int.rise(&readds);
Piasiv1206 0:58ec354d3b79 160
Piasiv1206 0:58ec354d3b79 161 while(1)
Piasiv1206 0:58ec354d3b79 162 {
Piasiv1206 0:58ec354d3b79 163 FUNC_MASTER_WRITE();
Piasiv1206 0:58ec354d3b79 164 wait(1);
Piasiv1206 2:623747e75e3c 165 //dt1 = rdata[0] ;
Piasiv1206 2:623747e75e3c 166 //dt2 = rdata[1] ;
Piasiv1206 2:623747e75e3c 167 for(P = 0 ; P < 26 ; P++ )
Piasiv1206 2:623747e75e3c 168 {
Piasiv1206 2:623747e75e3c 169 pc.printf("Temperature %d \n\r",rdata[P]);
Piasiv1206 2:623747e75e3c 170 }
Piasiv1206 2:623747e75e3c 171 // pc.printf("Temperature %d \n\r",dt1);
Piasiv1206 2:623747e75e3c 172 // pc.printf("Temperature2 %d \n\r",dt2);
Piasiv1206 0:58ec354d3b79 173 //pc.printf("Temperature3 %d \n\r",dt3);
Piasiv1206 0:58ec354d3b79 174
Piasiv1206 0:58ec354d3b79 175
Piasiv1206 0:58ec354d3b79 176 }
Piasiv1206 0:58ec354d3b79 177 }