PYLD_CDMS

Dependencies:   mbed

Fork of PLYD_CDMSee by Siva ram

Committer:
Piasiv1206
Date:
Sat Nov 07 09:52:57 2015 +0000
Revision:
4:ec3f71ef8732
Parent:
3:d2307fb2455c
Child:
5:f22f960f804b
holsdjlf;

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