PYLD_CDMS

Dependencies:   mbed

Fork of PLYD_CDMS_1_2 by Siva ram

Committer:
Piasiv1206
Date:
Tue Jun 30 07:40:20 2015 +0000
Revision:
0:58ec354d3b79
Child:
1:72227bdac415
PYLD_CDMS working

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 0:58ec354d3b79 8
Piasiv1206 0:58ec354d3b79 9 void FUNC_MASTER_WRITE(void);
Piasiv1206 0:58ec354d3b79 10 const int addr = 0x20<<1;
Piasiv1206 0:58ec354d3b79 11 Timer Siv ;
Piasiv1206 0:58ec354d3b79 12 I2C master (D14,D15);
Piasiv1206 0:58ec354d3b79 13 InterruptIn PYLD_I2C_Int(PTA13);
Piasiv1206 0:58ec354d3b79 14 SPISlave device(PTD6, PTD7, PTD5,PTD4 ); // mosi, miso, sclk, ssel --> using SPI1
Piasiv1206 0:58ec354d3b79 15 InterruptIn PYLD_SPI_Interrupt(PTD2);
Piasiv1206 0:58ec354d3b79 16 int payloadBins = 32;
Piasiv1206 0:58ec354d3b79 17 float Stability_delay = 0.005228 ;// 0.005228
Piasiv1206 0:58ec354d3b79 18
Piasiv1206 0:58ec354d3b79 19 Serial pc(USBTX, USBRX); // tx, rx --> serial feedback for debug
Piasiv1206 0:58ec354d3b79 20
Piasiv1206 0:58ec354d3b79 21 void payloadProcess() {
Piasiv1206 0:58ec354d3b79 22
Piasiv1206 0:58ec354d3b79 23
Piasiv1206 0:58ec354d3b79 24 //wait(Stability_delay); // wait after interrupt for stability
Piasiv1206 0:58ec354d3b79 25 unsigned short scienceRawPacket[payloadBins];
Piasiv1206 0:58ec354d3b79 26
Piasiv1206 0:58ec354d3b79 27 for(int i=0; i<payloadBins;i++){
Piasiv1206 0:58ec354d3b79 28
Piasiv1206 0:58ec354d3b79 29
Piasiv1206 0:58ec354d3b79 30
Piasiv1206 0:58ec354d3b79 31 while(!device.receive()); // blocking statement --> waiting for data from Payload
Piasiv1206 0:58ec354d3b79 32 scienceRawPacket[i] = device.read(); // Read byte from master
Piasiv1206 0:58ec354d3b79 33
Piasiv1206 0:58ec354d3b79 34 }
Piasiv1206 0:58ec354d3b79 35 // serial feedback
Piasiv1206 0:58ec354d3b79 36 pc.printf("Packet recieved\r\n");
Piasiv1206 0:58ec354d3b79 37 for(int i=0;i<payloadBins;i++){
Piasiv1206 0:58ec354d3b79 38 pc.printf("%d\t",scienceRawPacket[i]);
Piasiv1206 0:58ec354d3b79 39 scienceRawPacket[i] = 0;
Piasiv1206 0:58ec354d3b79 40 }
Piasiv1206 0:58ec354d3b79 41 pc.printf("\r\n");
Piasiv1206 0:58ec354d3b79 42
Piasiv1206 0:58ec354d3b79 43 }
Piasiv1206 0:58ec354d3b79 44 int dt3;
Piasiv1206 0:58ec354d3b79 45 bool f = 1;
Piasiv1206 0:58ec354d3b79 46 char rdata[10],rdata2;
Piasiv1206 0:58ec354d3b79 47 void readds()
Piasiv1206 0:58ec354d3b79 48 {
Piasiv1206 0:58ec354d3b79 49
Piasiv1206 0:58ec354d3b79 50 //wait(Stability_delay);
Piasiv1206 0:58ec354d3b79 51
Piasiv1206 0:58ec354d3b79 52 f = master.read(addr,rdata,2);
Piasiv1206 0:58ec354d3b79 53 // dt3 = master.read(1);
Piasiv1206 0:58ec354d3b79 54
Piasiv1206 0:58ec354d3b79 55
Piasiv1206 0:58ec354d3b79 56 }
Piasiv1206 0:58ec354d3b79 57
Piasiv1206 0:58ec354d3b79 58 int loop=1;
Piasiv1206 0:58ec354d3b79 59 char *writedata = new char;
Piasiv1206 0:58ec354d3b79 60 char data[8]= "payload";
Piasiv1206 0:58ec354d3b79 61
Piasiv1206 0:58ec354d3b79 62 void FUNC_MASTER_WRITE(void)
Piasiv1206 0:58ec354d3b79 63 { int data = pc.getc();
Piasiv1206 0:58ec354d3b79 64 loop=1;
Piasiv1206 0:58ec354d3b79 65
Piasiv1206 0:58ec354d3b79 66
Piasiv1206 0:58ec354d3b79 67 master.frequency(100000);
Piasiv1206 0:58ec354d3b79 68 *writedata = data;
Piasiv1206 0:58ec354d3b79 69 while(loop)
Piasiv1206 0:58ec354d3b79 70 {
Piasiv1206 0:58ec354d3b79 71 bool check = (bool)master.write(addr,writedata,1);
Piasiv1206 0:58ec354d3b79 72
Piasiv1206 0:58ec354d3b79 73 loop = 0;
Piasiv1206 0:58ec354d3b79 74 }
Piasiv1206 0:58ec354d3b79 75 }
Piasiv1206 0:58ec354d3b79 76 int main() {
Piasiv1206 0:58ec354d3b79 77 int dt1 = 0,dt2 = 0;
Piasiv1206 0:58ec354d3b79 78 device.format(16,0); // SPI format --> 16 bits, mode = 0
Piasiv1206 0:58ec354d3b79 79 device.frequency(1000000);
Piasiv1206 0:58ec354d3b79 80
Piasiv1206 0:58ec354d3b79 81 pc.printf("Example code demonstarting Payload - CDMS SPI & I2C communication!\r\n");
Piasiv1206 0:58ec354d3b79 82 PYLD_SPI_Interrupt.rise(&payloadProcess);
Piasiv1206 0:58ec354d3b79 83 PYLD_I2C_Int.rise(&readds);
Piasiv1206 0:58ec354d3b79 84
Piasiv1206 0:58ec354d3b79 85 while(1)
Piasiv1206 0:58ec354d3b79 86 {
Piasiv1206 0:58ec354d3b79 87 FUNC_MASTER_WRITE();
Piasiv1206 0:58ec354d3b79 88 wait(1);
Piasiv1206 0:58ec354d3b79 89 dt1 = rdata[0] ;
Piasiv1206 0:58ec354d3b79 90 dt2 = rdata[1] ;
Piasiv1206 0:58ec354d3b79 91 //pc.printf("Temperature %d \n\r",rdata);
Piasiv1206 0:58ec354d3b79 92 pc.printf("Temperature %d \n\r",dt1);
Piasiv1206 0:58ec354d3b79 93 pc.printf("Temperature2 %d \n\r",dt2);
Piasiv1206 0:58ec354d3b79 94 //pc.printf("Temperature3 %d \n\r",dt3);
Piasiv1206 0:58ec354d3b79 95
Piasiv1206 0:58ec354d3b79 96
Piasiv1206 0:58ec354d3b79 97 }
Piasiv1206 0:58ec354d3b79 98 }