Siva ram
/
PLYD_CDMSf
PYLD_CDMS
Fork of PLYD_CDMS24 by
main.cpp@6:090151fca074, 2016-02-27 (annotated)
- Committer:
- Piasiv1206
- Date:
- Sat Feb 27 07:16:16 2016 +0000
- Revision:
- 6:090151fca074
- Parent:
- 5:f22f960f804b
hello;
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 | 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 | 5:f22f960f804b | 15 | int FLAG = 1 ; |
Piasiv1206 | 0:58ec354d3b79 | 16 | I2C master (D14,D15); |
Piasiv1206 | 0:58ec354d3b79 | 17 | InterruptIn PYLD_I2C_Int(PTA13); |
Piasiv1206 | 4:ec3f71ef8732 | 18 | //gitalIn test(PTA13); |
Piasiv1206 | 0:58ec354d3b79 | 19 | SPISlave device(PTD6, PTD7, PTD5,PTD4 ); // mosi, miso, sclk, ssel --> using SPI1 |
Piasiv1206 | 4:ec3f71ef8732 | 20 | InterruptIn PYLD_SPI_Interrupt(PTD2); |
Piasiv1206 | 2:623747e75e3c | 21 | DigitalOut flash(LED4); |
Piasiv1206 | 5:f22f960f804b | 22 | int payloadBins = 1024; |
Piasiv1206 | 0:58ec354d3b79 | 23 | float Stability_delay = 0.005228 ;// 0.005228 |
Piasiv1206 | 5:f22f960f804b | 24 | #define CRC16 0x8010 |
Piasiv1206 | 5:f22f960f804b | 25 | |
Piasiv1206 | 5:f22f960f804b | 26 | uint16_t CRC_16_Calc(const char *data, uint16_t size); |
Piasiv1206 | 0:58ec354d3b79 | 27 | |
Piasiv1206 | 0:58ec354d3b79 | 28 | Serial pc(USBTX, USBRX); // tx, rx --> serial feedback for debug |
Piasiv1206 | 0:58ec354d3b79 | 29 | |
Piasiv1206 | 0:58ec354d3b79 | 30 | void payloadProcess() { |
Piasiv1206 | 0:58ec354d3b79 | 31 | |
Piasiv1206 | 5:f22f960f804b | 32 | flash = !flash; |
Piasiv1206 | 0:58ec354d3b79 | 33 | //wait(Stability_delay); // wait after interrupt for stability |
Piasiv1206 | 0:58ec354d3b79 | 34 | unsigned short scienceRawPacket[payloadBins]; |
Piasiv1206 | 0:58ec354d3b79 | 35 | |
Piasiv1206 | 0:58ec354d3b79 | 36 | for(int i=0; i<payloadBins;i++){ |
Piasiv1206 | 0:58ec354d3b79 | 37 | |
Piasiv1206 | 0:58ec354d3b79 | 38 | |
Piasiv1206 | 0:58ec354d3b79 | 39 | |
Piasiv1206 | 0:58ec354d3b79 | 40 | while(!device.receive()); // blocking statement --> waiting for data from Payload |
Piasiv1206 | 0:58ec354d3b79 | 41 | scienceRawPacket[i] = device.read(); // Read byte from master |
Piasiv1206 | 0:58ec354d3b79 | 42 | |
Piasiv1206 | 0:58ec354d3b79 | 43 | } |
Piasiv1206 | 0:58ec354d3b79 | 44 | // serial feedback |
Piasiv1206 | 0:58ec354d3b79 | 45 | pc.printf("Packet recieved\r\n"); |
Piasiv1206 | 0:58ec354d3b79 | 46 | for(int i=0;i<payloadBins;i++){ |
Piasiv1206 | 0:58ec354d3b79 | 47 | pc.printf("%d\t",scienceRawPacket[i]); |
Piasiv1206 | 0:58ec354d3b79 | 48 | scienceRawPacket[i] = 0; |
Piasiv1206 | 0:58ec354d3b79 | 49 | } |
Piasiv1206 | 0:58ec354d3b79 | 50 | pc.printf("\r\n"); |
Piasiv1206 | 0:58ec354d3b79 | 51 | |
Piasiv1206 | 0:58ec354d3b79 | 52 | } |
Piasiv1206 | 3:d2307fb2455c | 53 | int dt3,pia = 0; |
Piasiv1206 | 0:58ec354d3b79 | 54 | bool f = 1; |
Piasiv1206 | 4:ec3f71ef8732 | 55 | char rdata[140],ta2; |
Piasiv1206 | 5:f22f960f804b | 56 | int loop=1; |
Piasiv1206 | 5:f22f960f804b | 57 | char *writedata = new char; |
Piasiv1206 | 5:f22f960f804b | 58 | char data = 1,data1 = 2, data2 = 3, test[136] ; |
Piasiv1206 | 5:f22f960f804b | 59 | char pia1[13] , siv[13] ; |
Piasiv1206 | 0:58ec354d3b79 | 60 | void readds() |
Piasiv1206 | 0:58ec354d3b79 | 61 | { |
Piasiv1206 | 0:58ec354d3b79 | 62 | |
Piasiv1206 | 0:58ec354d3b79 | 63 | //wait(Stability_delay); |
Piasiv1206 | 2:623747e75e3c | 64 | flash = !flash; |
Piasiv1206 | 2:623747e75e3c | 65 | |
Piasiv1206 | 0:58ec354d3b79 | 66 | |
Piasiv1206 | 2:623747e75e3c | 67 | |
Piasiv1206 | 2:623747e75e3c | 68 | //while(!f) |
Piasiv1206 | 2:623747e75e3c | 69 | //{ |
Piasiv1206 | 5:f22f960f804b | 70 | f= master.read(addr1,siv,13); |
Piasiv1206 | 2:623747e75e3c | 71 | //} |
Piasiv1206 | 4:ec3f71ef8732 | 72 | // master.start(); |
Piasiv1206 | 4:ec3f71ef8732 | 73 | //for(int i = 0;i<26;i++) |
Piasiv1206 | 4:ec3f71ef8732 | 74 | //{ |
Piasiv1206 | 3:d2307fb2455c | 75 | |
Piasiv1206 | 4:ec3f71ef8732 | 76 | // master.write(addr2); |
Piasiv1206 | 4:ec3f71ef8732 | 77 | |
Piasiv1206 | 4:ec3f71ef8732 | 78 | // rdata[i] = master.read(1); |
Piasiv1206 | 4:ec3f71ef8732 | 79 | //wait_us(20); |
Piasiv1206 | 4:ec3f71ef8732 | 80 | |
Piasiv1206 | 2:623747e75e3c | 81 | |
Piasiv1206 | 4:ec3f71ef8732 | 82 | // } |
Piasiv1206 | 3:d2307fb2455c | 83 | |
Piasiv1206 | 4:ec3f71ef8732 | 84 | // master.stop(); |
Piasiv1206 | 3:d2307fb2455c | 85 | /* |
Piasiv1206 | 3:d2307fb2455c | 86 | for(pia = 0 ;pia<26;pia ++) |
Piasiv1206 | 3:d2307fb2455c | 87 | { |
Piasiv1206 | 3:d2307fb2455c | 88 | master.read(addr1,&rdata[pia],1); |
Piasiv1206 | 3:d2307fb2455c | 89 | } |
Piasiv1206 | 3:d2307fb2455c | 90 | */ |
Piasiv1206 | 0:58ec354d3b79 | 91 | // dt3 = master.read(1); |
Piasiv1206 | 0:58ec354d3b79 | 92 | |
Piasiv1206 | 0:58ec354d3b79 | 93 | |
Piasiv1206 | 0:58ec354d3b79 | 94 | } |
Piasiv1206 | 0:58ec354d3b79 | 95 | |
Piasiv1206 | 5:f22f960f804b | 96 | |
Piasiv1206 | 5:f22f960f804b | 97 | |
Piasiv1206 | 5:f22f960f804b | 98 | void INIT_TC_TEMP (void) |
Piasiv1206 | 5:f22f960f804b | 99 | { |
Piasiv1206 | 5:f22f960f804b | 100 | |
Piasiv1206 | 5:f22f960f804b | 101 | uint16_t CRC_VALUE = 0 ; |
Piasiv1206 | 5:f22f960f804b | 102 | |
Piasiv1206 | 5:f22f960f804b | 103 | pia1[0] = 123 ; |
Piasiv1206 | 6:090151fca074 | 104 | pia1[1] = 0xff ; |
Piasiv1206 | 5:f22f960f804b | 105 | pia1[2] = 0x81 ; |
Piasiv1206 | 5:f22f960f804b | 106 | pia1[3] = 0xD0 ; |
Piasiv1206 | 5:f22f960f804b | 107 | pia1[4] = 0x00 ; |
Piasiv1206 | 5:f22f960f804b | 108 | pia1[5] = 0x00 ; |
Piasiv1206 | 5:f22f960f804b | 109 | pia1[6] = 0x00 ; |
Piasiv1206 | 5:f22f960f804b | 110 | pia1[7] = 0x00 ; |
Piasiv1206 | 5:f22f960f804b | 111 | pia1[8] = 0x00 ; |
Piasiv1206 | 5:f22f960f804b | 112 | CRC_VALUE = CRC_16_Calc(pia1,9) ; |
Piasiv1206 | 5:f22f960f804b | 113 | pia1[9] = (char)((CRC_VALUE >> 8) & 0xff); |
Piasiv1206 | 5:f22f960f804b | 114 | pia1[10] = (char)((CRC_VALUE >> 0) & 0xff); |
Piasiv1206 | 5:f22f960f804b | 115 | |
Piasiv1206 | 5:f22f960f804b | 116 | |
Piasiv1206 | 5:f22f960f804b | 117 | } |
Piasiv1206 | 5:f22f960f804b | 118 | |
Piasiv1206 | 5:f22f960f804b | 119 | int CHECK_TM (void) |
Piasiv1206 | 5:f22f960f804b | 120 | { |
Piasiv1206 | 5:f22f960f804b | 121 | uint16_t CRC_Value = 0 , check = 0; |
Piasiv1206 | 5:f22f960f804b | 122 | CRC_Value = CRC_Value | ((uint16_t) siv[11]) ; |
Piasiv1206 | 5:f22f960f804b | 123 | CRC_Value = CRC_Value << 8; |
Piasiv1206 | 5:f22f960f804b | 124 | CRC_Value = CRC_Value | ((uint16_t) siv[12]) ; |
Piasiv1206 | 5:f22f960f804b | 125 | if (CRC_Value == CRC_16_Calc (siv,11)) |
Piasiv1206 | 5:f22f960f804b | 126 | { |
Piasiv1206 | 5:f22f960f804b | 127 | check++; |
Piasiv1206 | 5:f22f960f804b | 128 | } |
Piasiv1206 | 5:f22f960f804b | 129 | else |
Piasiv1206 | 5:f22f960f804b | 130 | { |
Piasiv1206 | 5:f22f960f804b | 131 | return(10); |
Piasiv1206 | 5:f22f960f804b | 132 | } |
Piasiv1206 | 5:f22f960f804b | 133 | if ( siv[1] == 123 ) |
Piasiv1206 | 5:f22f960f804b | 134 | { |
Piasiv1206 | 5:f22f960f804b | 135 | check++; |
Piasiv1206 | 5:f22f960f804b | 136 | } |
Piasiv1206 | 5:f22f960f804b | 137 | else |
Piasiv1206 | 5:f22f960f804b | 138 | { |
Piasiv1206 | 5:f22f960f804b | 139 | return (9); |
Piasiv1206 | 5:f22f960f804b | 140 | } |
Piasiv1206 | 6:090151fca074 | 141 | if ( siv[3] == 160 ) |
Piasiv1206 | 5:f22f960f804b | 142 | { |
Piasiv1206 | 5:f22f960f804b | 143 | check ++ ; |
Piasiv1206 | 5:f22f960f804b | 144 | } |
Piasiv1206 | 5:f22f960f804b | 145 | else |
Piasiv1206 | 5:f22f960f804b | 146 | { |
Piasiv1206 | 5:f22f960f804b | 147 | return (8); |
Piasiv1206 | 5:f22f960f804b | 148 | } |
Piasiv1206 | 5:f22f960f804b | 149 | |
Piasiv1206 | 5:f22f960f804b | 150 | FLAG = 0 ; |
Piasiv1206 | 5:f22f960f804b | 151 | return (check) ; |
Piasiv1206 | 5:f22f960f804b | 152 | } |
Piasiv1206 | 5:f22f960f804b | 153 | |
Piasiv1206 | 5:f22f960f804b | 154 | uint16_t CRC_16_Calc(const char *data, uint16_t size) |
Piasiv1206 | 5:f22f960f804b | 155 | { |
Piasiv1206 | 5:f22f960f804b | 156 | uint16_t CRC_OUT = 0; |
Piasiv1206 | 5:f22f960f804b | 157 | int bits_read = 0, bit_flag; |
Piasiv1206 | 5:f22f960f804b | 158 | |
Piasiv1206 | 5:f22f960f804b | 159 | |
Piasiv1206 | 5:f22f960f804b | 160 | |
Piasiv1206 | 5:f22f960f804b | 161 | while(size > 0) |
Piasiv1206 | 5:f22f960f804b | 162 | { |
Piasiv1206 | 5:f22f960f804b | 163 | bit_flag = CRC_OUT >> 15; |
Piasiv1206 | 5:f22f960f804b | 164 | |
Piasiv1206 | 5:f22f960f804b | 165 | /* Get next bit: */ |
Piasiv1206 | 5:f22f960f804b | 166 | CRC_OUT <<= 1; |
Piasiv1206 | 5:f22f960f804b | 167 | CRC_OUT |= (*data >> (7 - bits_read)) & 1; |
Piasiv1206 | 5:f22f960f804b | 168 | |
Piasiv1206 | 5:f22f960f804b | 169 | /* Increment bit counter: */ |
Piasiv1206 | 5:f22f960f804b | 170 | bits_read++; |
Piasiv1206 | 5:f22f960f804b | 171 | if(bits_read > 7) |
Piasiv1206 | 5:f22f960f804b | 172 | { |
Piasiv1206 | 5:f22f960f804b | 173 | bits_read = 0; |
Piasiv1206 | 5:f22f960f804b | 174 | data++; |
Piasiv1206 | 5:f22f960f804b | 175 | size--; |
Piasiv1206 | 5:f22f960f804b | 176 | } |
Piasiv1206 | 5:f22f960f804b | 177 | |
Piasiv1206 | 5:f22f960f804b | 178 | /* Cycle check: */ |
Piasiv1206 | 5:f22f960f804b | 179 | if(bit_flag) |
Piasiv1206 | 5:f22f960f804b | 180 | CRC_OUT ^= CRC16; |
Piasiv1206 | 5:f22f960f804b | 181 | |
Piasiv1206 | 5:f22f960f804b | 182 | } |
Piasiv1206 | 5:f22f960f804b | 183 | return CRC_OUT; |
Piasiv1206 | 5:f22f960f804b | 184 | } |
Piasiv1206 | 2:623747e75e3c | 185 | |
Piasiv1206 | 0:58ec354d3b79 | 186 | |
Piasiv1206 | 0:58ec354d3b79 | 187 | void FUNC_MASTER_WRITE(void) |
Piasiv1206 | 2:623747e75e3c | 188 | { |
Piasiv1206 | 2:623747e75e3c | 189 | |
Piasiv1206 | 4:ec3f71ef8732 | 190 | for (dt3 = 0;dt3 <135 ; dt3++) |
Piasiv1206 | 2:623747e75e3c | 191 | { |
Piasiv1206 | 3:d2307fb2455c | 192 | test [dt3] = dt3 ; |
Piasiv1206 | 2:623747e75e3c | 193 | } |
Piasiv1206 | 2:623747e75e3c | 194 | int data5 = pc.getc(); |
Piasiv1206 | 0:58ec354d3b79 | 195 | loop=1; |
Piasiv1206 | 0:58ec354d3b79 | 196 | |
Piasiv1206 | 0:58ec354d3b79 | 197 | |
Piasiv1206 | 0:58ec354d3b79 | 198 | master.frequency(100000); |
Piasiv1206 | 1:72227bdac415 | 199 | *writedata = data1; |
Piasiv1206 | 0:58ec354d3b79 | 200 | while(loop) |
Piasiv1206 | 0:58ec354d3b79 | 201 | { |
Piasiv1206 | 2:623747e75e3c | 202 | |
Piasiv1206 | 5:f22f960f804b | 203 | bool check = (bool)master.write(addr,pia1,11); |
Piasiv1206 | 3:d2307fb2455c | 204 | // bool check = (bool)master.write(addr,&test[3],1,false); |
Piasiv1206 | 3:d2307fb2455c | 205 | // check = (bool)master.write(addr,&test[4],1); |
Piasiv1206 | 2:623747e75e3c | 206 | |
Piasiv1206 | 2:623747e75e3c | 207 | //wait_us(10); |
Piasiv1206 | 2:623747e75e3c | 208 | |
Piasiv1206 | 2:623747e75e3c | 209 | //check = (bool)master.write(addr,&data1,1); |
Piasiv1206 | 2:623747e75e3c | 210 | // check = (bool)master.write(addr,&data1,1); |
Piasiv1206 | 2:623747e75e3c | 211 | //check = (bool)master.write(addr,&data2,1); |
Piasiv1206 | 2:623747e75e3c | 212 | //bool check = master.write(addr,test,3); |
Piasiv1206 | 2:623747e75e3c | 213 | |
Piasiv1206 | 2:623747e75e3c | 214 | // while(!test); |
Piasiv1206 | 2:623747e75e3c | 215 | |
Piasiv1206 | 2:623747e75e3c | 216 | // readds(); |
Piasiv1206 | 3:d2307fb2455c | 217 | /* |
Piasiv1206 | 3:d2307fb2455c | 218 | master.start(); |
Piasiv1206 | 3:d2307fb2455c | 219 | master.write(addr1); |
Piasiv1206 | 3:d2307fb2455c | 220 | |
Piasiv1206 | 3:d2307fb2455c | 221 | for( pia = 0 ; pia<2 ; pia++) |
Piasiv1206 | 3:d2307fb2455c | 222 | { |
Piasiv1206 | 3:d2307fb2455c | 223 | |
Piasiv1206 | 3:d2307fb2455c | 224 | master.write(test[pia]); |
Piasiv1206 | 3:d2307fb2455c | 225 | //wait_us(2); |
Piasiv1206 | 3:d2307fb2455c | 226 | |
Piasiv1206 | 3:d2307fb2455c | 227 | |
Piasiv1206 | 3:d2307fb2455c | 228 | } |
Piasiv1206 | 3:d2307fb2455c | 229 | |
Piasiv1206 | 3:d2307fb2455c | 230 | |
Piasiv1206 | 3:d2307fb2455c | 231 | |
Piasiv1206 | 3:d2307fb2455c | 232 | |
Piasiv1206 | 3:d2307fb2455c | 233 | for( pia = 2 ; pia<13 ; pia++) |
Piasiv1206 | 3:d2307fb2455c | 234 | { |
Piasiv1206 | 3:d2307fb2455c | 235 | |
Piasiv1206 | 3:d2307fb2455c | 236 | master.write(test[pia]); |
Piasiv1206 | 3:d2307fb2455c | 237 | //wait_us(2); |
Piasiv1206 | 3:d2307fb2455c | 238 | |
Piasiv1206 | 3:d2307fb2455c | 239 | |
Piasiv1206 | 3:d2307fb2455c | 240 | } |
Piasiv1206 | 3:d2307fb2455c | 241 | master.stop(); |
Piasiv1206 | 3:d2307fb2455c | 242 | |
Piasiv1206 | 3:d2307fb2455c | 243 | */ |
Piasiv1206 | 3:d2307fb2455c | 244 | /* |
Piasiv1206 | 3:d2307fb2455c | 245 | master.start(); |
Piasiv1206 | 3:d2307fb2455c | 246 | bool check1 = master.write(addr1); |
Piasiv1206 | 2:623747e75e3c | 247 | // wait_us(10); |
Piasiv1206 | 3:d2307fb2455c | 248 | bool check2 = master.write(1); |
Piasiv1206 | 2:623747e75e3c | 249 | //wait_us(10); |
Piasiv1206 | 3:d2307fb2455c | 250 | check2 = master.write(2); |
Piasiv1206 | 3:d2307fb2455c | 251 | master.write(3); |
Piasiv1206 | 3:d2307fb2455c | 252 | master.write(4); |
Piasiv1206 | 3:d2307fb2455c | 253 | master.write(5); |
Piasiv1206 | 3:d2307fb2455c | 254 | master.write(6); |
Piasiv1206 | 3:d2307fb2455c | 255 | master.write(7); |
Piasiv1206 | 2:623747e75e3c | 256 | //wait_us(10); |
Piasiv1206 | 3:d2307fb2455c | 257 | master.write(8); |
Piasiv1206 | 3:d2307fb2455c | 258 | master.write(9); |
Piasiv1206 | 3:d2307fb2455c | 259 | master.write(10); |
Piasiv1206 | 3:d2307fb2455c | 260 | master.write(11); |
Piasiv1206 | 3:d2307fb2455c | 261 | master.write(12); |
Piasiv1206 | 3:d2307fb2455c | 262 | master.write(13); |
Piasiv1206 | 2:623747e75e3c | 263 | |
Piasiv1206 | 3:d2307fb2455c | 264 | master.stop(); |
Piasiv1206 | 2:623747e75e3c | 265 | |
Piasiv1206 | 3:d2307fb2455c | 266 | */ |
Piasiv1206 | 1:72227bdac415 | 267 | |
Piasiv1206 | 0:58ec354d3b79 | 268 | |
Piasiv1206 | 0:58ec354d3b79 | 269 | loop = 0; |
Piasiv1206 | 0:58ec354d3b79 | 270 | } |
Piasiv1206 | 0:58ec354d3b79 | 271 | } |
Piasiv1206 | 2:623747e75e3c | 272 | |
Piasiv1206 | 0:58ec354d3b79 | 273 | int main() { |
Piasiv1206 | 2:623747e75e3c | 274 | int dt1 = 0,dt2 = 0 ,P= 0; |
Piasiv1206 | 4:ec3f71ef8732 | 275 | device.format(16,0); // SPI format --> 16 bits, mode = 0 |
Piasiv1206 | 4:ec3f71ef8732 | 276 | device.frequency(1000000); |
Piasiv1206 | 3:d2307fb2455c | 277 | master.frequency(400000); |
Piasiv1206 | 0:58ec354d3b79 | 278 | |
Piasiv1206 | 0:58ec354d3b79 | 279 | pc.printf("Example code demonstarting Payload - CDMS SPI & I2C communication!\r\n"); |
Piasiv1206 | 4:ec3f71ef8732 | 280 | PYLD_SPI_Interrupt.rise(&payloadProcess); |
Piasiv1206 | 0:58ec354d3b79 | 281 | PYLD_I2C_Int.rise(&readds); |
Piasiv1206 | 5:f22f960f804b | 282 | INIT_TC_TEMP(); |
Piasiv1206 | 0:58ec354d3b79 | 283 | |
Piasiv1206 | 6:090151fca074 | 284 | |
Piasiv1206 | 0:58ec354d3b79 | 285 | while(1) |
Piasiv1206 | 0:58ec354d3b79 | 286 | { |
Piasiv1206 | 0:58ec354d3b79 | 287 | FUNC_MASTER_WRITE(); |
Piasiv1206 | 0:58ec354d3b79 | 288 | wait(1); |
Piasiv1206 | 2:623747e75e3c | 289 | //dt1 = rdata[0] ; |
Piasiv1206 | 2:623747e75e3c | 290 | //dt2 = rdata[1] ; |
Piasiv1206 | 5:f22f960f804b | 291 | for(P = 0 ; P < 13 ; P++ ) |
Piasiv1206 | 2:623747e75e3c | 292 | { |
Piasiv1206 | 5:f22f960f804b | 293 | pc.printf("Temperature %d \n\r",siv[P]); |
Piasiv1206 | 5:f22f960f804b | 294 | } |
Piasiv1206 | 5:f22f960f804b | 295 | // while ( FLAG == 1) |
Piasiv1206 | 5:f22f960f804b | 296 | // {} |
Piasiv1206 | 5:f22f960f804b | 297 | pc.printf(" Packect Recieved \n \r"); |
Piasiv1206 | 5:f22f960f804b | 298 | |
Piasiv1206 | 5:f22f960f804b | 299 | if( CHECK_TM() == 3 ) |
Piasiv1206 | 5:f22f960f804b | 300 | { |
Piasiv1206 | 5:f22f960f804b | 301 | pc.printf(" ACK Recieved \n \r"); |
Piasiv1206 | 5:f22f960f804b | 302 | } |
Piasiv1206 | 5:f22f960f804b | 303 | else if ( CHECK_TM() == 10 ) |
Piasiv1206 | 5:f22f960f804b | 304 | { |
Piasiv1206 | 5:f22f960f804b | 305 | pc.printf("Error Code 10 : CRC_FAIL \n \r" ); |
Piasiv1206 | 5:f22f960f804b | 306 | } |
Piasiv1206 | 5:f22f960f804b | 307 | else if ( CHECK_TM() == 9 ) |
Piasiv1206 | 5:f22f960f804b | 308 | { |
Piasiv1206 | 5:f22f960f804b | 309 | pc.printf("Error Code 9 : PSC FAIL \n \r" ); |
Piasiv1206 | 5:f22f960f804b | 310 | } |
Piasiv1206 | 5:f22f960f804b | 311 | else if ( CHECK_TM() == 8 ) |
Piasiv1206 | 5:f22f960f804b | 312 | { |
Piasiv1206 | 5:f22f960f804b | 313 | pc.printf("Error Code 8 : NACK ACK FAIL \n \r" ); |
Piasiv1206 | 5:f22f960f804b | 314 | } |
Piasiv1206 | 5:f22f960f804b | 315 | wait (1) ; |
Piasiv1206 | 5:f22f960f804b | 316 | |
Piasiv1206 | 5:f22f960f804b | 317 | for(P = 0 ; P < 13 ; P++ ) |
Piasiv1206 | 5:f22f960f804b | 318 | { |
Piasiv1206 | 5:f22f960f804b | 319 | pc.printf("Temperature %d \n\r",siv[P]); |
Piasiv1206 | 5:f22f960f804b | 320 | } |
Piasiv1206 | 5:f22f960f804b | 321 | |
Piasiv1206 | 5:f22f960f804b | 322 | pc.printf(" Packect Recieved \n \r"); |
Piasiv1206 | 5:f22f960f804b | 323 | uint16_t CRC_Value = 0 ; |
Piasiv1206 | 5:f22f960f804b | 324 | CRC_Value = CRC_Value | (siv[11]) ; |
Piasiv1206 | 5:f22f960f804b | 325 | CRC_Value = CRC_Value << 8; |
Piasiv1206 | 5:f22f960f804b | 326 | CRC_Value = CRC_Value | (siv[12]) ; |
Piasiv1206 | 5:f22f960f804b | 327 | |
Piasiv1206 | 5:f22f960f804b | 328 | if (CRC_Value == CRC_16_Calc (siv,11)) |
Piasiv1206 | 5:f22f960f804b | 329 | { |
Piasiv1206 | 5:f22f960f804b | 330 | pc.printf("CRC_PASS Temperature of PYLD uC is : %d \n \r",siv[3]); |
Piasiv1206 | 5:f22f960f804b | 331 | } |
Piasiv1206 | 5:f22f960f804b | 332 | else |
Piasiv1206 | 5:f22f960f804b | 333 | { |
Piasiv1206 | 5:f22f960f804b | 334 | pc.printf("Data CRC_Fail \n \r"); |
Piasiv1206 | 5:f22f960f804b | 335 | } |
Piasiv1206 | 5:f22f960f804b | 336 | |
Piasiv1206 | 5:f22f960f804b | 337 | |
Piasiv1206 | 5:f22f960f804b | 338 | pc.printf(" I2C data register %d \n \r", I2C1 -> S); |
Piasiv1206 | 2:623747e75e3c | 339 | // pc.printf("Temperature %d \n\r",dt1); |
Piasiv1206 | 2:623747e75e3c | 340 | // pc.printf("Temperature2 %d \n\r",dt2); |
Piasiv1206 | 0:58ec354d3b79 | 341 | //pc.printf("Temperature3 %d \n\r",dt3); |
Piasiv1206 | 0:58ec354d3b79 | 342 | |
Piasiv1206 | 0:58ec354d3b79 | 343 | |
Piasiv1206 | 0:58ec354d3b79 | 344 | } |
Piasiv1206 | 0:58ec354d3b79 | 345 | } |