Siva ram
/
PLYD_CDMSee
PYLD_CDMS
Fork of PLYD_CDMS_1_2 by
main.cpp@1:72227bdac415, 2015-07-01 (annotated)
- Committer:
- Piasiv1206
- Date:
- Wed Jul 01 08:36:55 2015 +0000
- Revision:
- 1:72227bdac415
- Parent:
- 0:58ec354d3b79
- Child:
- 2:623747e75e3c
PYLD_CDMS I2C and SPI complete working... :-)
Who changed what in which revision?
User | Revision | Line number | New 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 | 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 | 0:58ec354d3b79 | 15 | SPISlave device(PTD6, PTD7, PTD5,PTD4 ); // mosi, miso, sclk, ssel --> using SPI1 |
Piasiv1206 | 0:58ec354d3b79 | 16 | InterruptIn PYLD_SPI_Interrupt(PTD2); |
Piasiv1206 | 0:58ec354d3b79 | 17 | int payloadBins = 32; |
Piasiv1206 | 0:58ec354d3b79 | 18 | float Stability_delay = 0.005228 ;// 0.005228 |
Piasiv1206 | 0:58ec354d3b79 | 19 | |
Piasiv1206 | 0:58ec354d3b79 | 20 | Serial pc(USBTX, USBRX); // tx, rx --> serial feedback for debug |
Piasiv1206 | 0:58ec354d3b79 | 21 | |
Piasiv1206 | 0:58ec354d3b79 | 22 | void payloadProcess() { |
Piasiv1206 | 0:58ec354d3b79 | 23 | |
Piasiv1206 | 0:58ec354d3b79 | 24 | |
Piasiv1206 | 0:58ec354d3b79 | 25 | //wait(Stability_delay); // wait after interrupt for stability |
Piasiv1206 | 0:58ec354d3b79 | 26 | unsigned short scienceRawPacket[payloadBins]; |
Piasiv1206 | 0:58ec354d3b79 | 27 | |
Piasiv1206 | 0:58ec354d3b79 | 28 | for(int i=0; i<payloadBins;i++){ |
Piasiv1206 | 0:58ec354d3b79 | 29 | |
Piasiv1206 | 0:58ec354d3b79 | 30 | |
Piasiv1206 | 0:58ec354d3b79 | 31 | |
Piasiv1206 | 0:58ec354d3b79 | 32 | while(!device.receive()); // blocking statement --> waiting for data from Payload |
Piasiv1206 | 0:58ec354d3b79 | 33 | scienceRawPacket[i] = device.read(); // Read byte from master |
Piasiv1206 | 0:58ec354d3b79 | 34 | |
Piasiv1206 | 0:58ec354d3b79 | 35 | } |
Piasiv1206 | 0:58ec354d3b79 | 36 | // serial feedback |
Piasiv1206 | 0:58ec354d3b79 | 37 | pc.printf("Packet recieved\r\n"); |
Piasiv1206 | 0:58ec354d3b79 | 38 | for(int i=0;i<payloadBins;i++){ |
Piasiv1206 | 0:58ec354d3b79 | 39 | pc.printf("%d\t",scienceRawPacket[i]); |
Piasiv1206 | 0:58ec354d3b79 | 40 | scienceRawPacket[i] = 0; |
Piasiv1206 | 0:58ec354d3b79 | 41 | } |
Piasiv1206 | 0:58ec354d3b79 | 42 | pc.printf("\r\n"); |
Piasiv1206 | 0:58ec354d3b79 | 43 | |
Piasiv1206 | 0:58ec354d3b79 | 44 | } |
Piasiv1206 | 0:58ec354d3b79 | 45 | int dt3; |
Piasiv1206 | 0:58ec354d3b79 | 46 | bool f = 1; |
Piasiv1206 | 0:58ec354d3b79 | 47 | char rdata[10],rdata2; |
Piasiv1206 | 0:58ec354d3b79 | 48 | void readds() |
Piasiv1206 | 0:58ec354d3b79 | 49 | { |
Piasiv1206 | 0:58ec354d3b79 | 50 | |
Piasiv1206 | 0:58ec354d3b79 | 51 | //wait(Stability_delay); |
Piasiv1206 | 0:58ec354d3b79 | 52 | |
Piasiv1206 | 0:58ec354d3b79 | 53 | f = master.read(addr,rdata,2); |
Piasiv1206 | 0:58ec354d3b79 | 54 | // dt3 = master.read(1); |
Piasiv1206 | 0:58ec354d3b79 | 55 | |
Piasiv1206 | 0:58ec354d3b79 | 56 | |
Piasiv1206 | 0:58ec354d3b79 | 57 | } |
Piasiv1206 | 0:58ec354d3b79 | 58 | |
Piasiv1206 | 0:58ec354d3b79 | 59 | int loop=1; |
Piasiv1206 | 0:58ec354d3b79 | 60 | char *writedata = new char; |
Piasiv1206 | 1:72227bdac415 | 61 | char data[100]= "kitten"; |
Piasiv1206 | 0:58ec354d3b79 | 62 | |
Piasiv1206 | 0:58ec354d3b79 | 63 | void FUNC_MASTER_WRITE(void) |
Piasiv1206 | 1:72227bdac415 | 64 | { int data1 = pc.getc(); |
Piasiv1206 | 0:58ec354d3b79 | 65 | loop=1; |
Piasiv1206 | 0:58ec354d3b79 | 66 | |
Piasiv1206 | 0:58ec354d3b79 | 67 | |
Piasiv1206 | 0:58ec354d3b79 | 68 | master.frequency(100000); |
Piasiv1206 | 1:72227bdac415 | 69 | *writedata = data1; |
Piasiv1206 | 0:58ec354d3b79 | 70 | while(loop) |
Piasiv1206 | 0:58ec354d3b79 | 71 | { |
Piasiv1206 | 1:72227bdac415 | 72 | // bool check = (bool)master.write(addr,data,8); |
Piasiv1206 | 1:72227bdac415 | 73 | bool check = (bool)master.write(addr,data,13); |
Piasiv1206 | 1:72227bdac415 | 74 | /* |
Piasiv1206 | 1:72227bdac415 | 75 | master.start(); |
Piasiv1206 | 1:72227bdac415 | 76 | bool check1 = master.write(addr1); |
Piasiv1206 | 1:72227bdac415 | 77 | bool check2 = master.write(83); |
Piasiv1206 | 1:72227bdac415 | 78 | master.write(97); |
Piasiv1206 | 1:72227bdac415 | 79 | //wait(1); |
Piasiv1206 | 1:72227bdac415 | 80 | master.write(107); |
Piasiv1206 | 1:72227bdac415 | 81 | master.write(116); |
Piasiv1206 | 1:72227bdac415 | 82 | master.write(104); |
Piasiv1206 | 1:72227bdac415 | 83 | master.write(105); |
Piasiv1206 | 1:72227bdac415 | 84 | master.write(32); |
Piasiv1206 | 1:72227bdac415 | 85 | master.write(80); |
Piasiv1206 | 1:72227bdac415 | 86 | master.write(114); |
Piasiv1206 | 1:72227bdac415 | 87 | master.write(105); |
Piasiv1206 | 1:72227bdac415 | 88 | master.write(121); |
Piasiv1206 | 1:72227bdac415 | 89 | master.write(97); |
Piasiv1206 | 1:72227bdac415 | 90 | |
Piasiv1206 | 1:72227bdac415 | 91 | master.stop(); |
Piasiv1206 | 1:72227bdac415 | 92 | */ |
Piasiv1206 | 1:72227bdac415 | 93 | |
Piasiv1206 | 0:58ec354d3b79 | 94 | |
Piasiv1206 | 0:58ec354d3b79 | 95 | loop = 0; |
Piasiv1206 | 0:58ec354d3b79 | 96 | } |
Piasiv1206 | 0:58ec354d3b79 | 97 | } |
Piasiv1206 | 0:58ec354d3b79 | 98 | int main() { |
Piasiv1206 | 0:58ec354d3b79 | 99 | int dt1 = 0,dt2 = 0; |
Piasiv1206 | 0:58ec354d3b79 | 100 | device.format(16,0); // SPI format --> 16 bits, mode = 0 |
Piasiv1206 | 0:58ec354d3b79 | 101 | device.frequency(1000000); |
Piasiv1206 | 1:72227bdac415 | 102 | master.frequency(400000); |
Piasiv1206 | 0:58ec354d3b79 | 103 | |
Piasiv1206 | 0:58ec354d3b79 | 104 | pc.printf("Example code demonstarting Payload - CDMS SPI & I2C communication!\r\n"); |
Piasiv1206 | 0:58ec354d3b79 | 105 | PYLD_SPI_Interrupt.rise(&payloadProcess); |
Piasiv1206 | 0:58ec354d3b79 | 106 | PYLD_I2C_Int.rise(&readds); |
Piasiv1206 | 0:58ec354d3b79 | 107 | |
Piasiv1206 | 0:58ec354d3b79 | 108 | while(1) |
Piasiv1206 | 0:58ec354d3b79 | 109 | { |
Piasiv1206 | 0:58ec354d3b79 | 110 | FUNC_MASTER_WRITE(); |
Piasiv1206 | 0:58ec354d3b79 | 111 | wait(1); |
Piasiv1206 | 0:58ec354d3b79 | 112 | dt1 = rdata[0] ; |
Piasiv1206 | 0:58ec354d3b79 | 113 | dt2 = rdata[1] ; |
Piasiv1206 | 0:58ec354d3b79 | 114 | //pc.printf("Temperature %d \n\r",rdata); |
Piasiv1206 | 0:58ec354d3b79 | 115 | pc.printf("Temperature %d \n\r",dt1); |
Piasiv1206 | 0:58ec354d3b79 | 116 | pc.printf("Temperature2 %d \n\r",dt2); |
Piasiv1206 | 0:58ec354d3b79 | 117 | //pc.printf("Temperature3 %d \n\r",dt3); |
Piasiv1206 | 0:58ec354d3b79 | 118 | |
Piasiv1206 | 0:58ec354d3b79 | 119 | |
Piasiv1206 | 0:58ec354d3b79 | 120 | } |
Piasiv1206 | 0:58ec354d3b79 | 121 | } |