![](/media/cache/group/AET.jpg.50x50_q85.jpg)
Maček Dorijan Miljković Dominik Napon i temperatura sa istog slave-a
Dependencies: Display1602 mbed-rtos mbed nRF24L01P
main.cpp@3:07d5ce3c32e3, 2016-01-28 (annotated)
- Committer:
- DorijanMacek
- Date:
- Thu Jan 28 16:46:15 2016 +0000
- Revision:
- 3:07d5ce3c32e3
- Parent:
- 2:d0f85a573b89
Ma?ek Dorijan ; Miljkovi? Dominik; Napon i temperatura sa istog slave-a;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DorijanMacek | 0:d74d1d840f60 | 1 | #include "mbed.h" |
DorijanMacek | 1:0f605b9eed83 | 2 | #include "rtos.h" |
DorijanMacek | 0:d74d1d840f60 | 3 | #include "nRF24L01P.h" |
DorijanMacek | 0:d74d1d840f60 | 4 | #include "Display1602.h" |
DorijanMacek | 0:d74d1d840f60 | 5 | |
DorijanMacek | 3:07d5ce3c32e3 | 6 | //Mutex stdio_mutex; |
DorijanMacek | 2:d0f85a573b89 | 7 | Semaphore semMSP430G(1); |
DorijanMacek | 2:d0f85a573b89 | 8 | Semaphore semLCD(1); |
DorijanMacek | 2:d0f85a573b89 | 9 | Semaphore semJoystick(1); |
DorijanMacek | 1:0f605b9eed83 | 10 | |
DorijanMacek | 0:d74d1d840f60 | 11 | |
DorijanMacek | 0:d74d1d840f60 | 12 | I2C MSP430G(p9, p10); //sda, sc1 |
DorijanMacek | 0:d74d1d840f60 | 13 | nRF24L01P odasiljac(p11,p12,p13,p14,p28,p27); //// mosi, miso, sck, csn, ce, irq |
DorijanMacek | 0:d74d1d840f60 | 14 | AnalogIn upDown(p15); |
DorijanMacek | 0:d74d1d840f60 | 15 | AnalogIn leftRight(p16); |
DorijanMacek | 0:d74d1d840f60 | 16 | Display1602 display(p19, p20, p21, p22, p23, p24,p25,p26,p29,p30,p18); |
DorijanMacek | 0:d74d1d840f60 | 17 | Serial pc(USBTX, USBRX); |
DorijanMacek | 0:d74d1d840f60 | 18 | |
DorijanMacek | 0:d74d1d840f60 | 19 | DigitalOut myled1(LED1); |
DorijanMacek | 0:d74d1d840f60 | 20 | DigitalOut myled2(LED2); |
DorijanMacek | 0:d74d1d840f60 | 21 | DigitalOut myled3(LED3); |
DorijanMacek | 0:d74d1d840f60 | 22 | DigitalOut myled4(LED4); |
DorijanMacek | 3:07d5ce3c32e3 | 23 | DigitalOut res(p17); |
DorijanMacek | 0:d74d1d840f60 | 24 | |
DorijanMacek | 0:d74d1d840f60 | 25 | void startLCD(void); |
DorijanMacek | 0:d74d1d840f60 | 26 | void startNRF(int); |
DorijanMacek | 1:0f605b9eed83 | 27 | |
DorijanMacek | 1:0f605b9eed83 | 28 | void printTempAndVoltOnLCD(void const *args); |
DorijanMacek | 1:0f605b9eed83 | 29 | void printJoystickOnLCD(void const *args); |
DorijanMacek | 1:0f605b9eed83 | 30 | |
DorijanMacek | 1:0f605b9eed83 | 31 | void readJoystick(void const *args); |
DorijanMacek | 1:0f605b9eed83 | 32 | void readTempFromMSP430G(void const *args); |
DorijanMacek | 1:0f605b9eed83 | 33 | void readVoltFromMSP430G(void const *args); |
DorijanMacek | 1:0f605b9eed83 | 34 | |
DorijanMacek | 1:0f605b9eed83 | 35 | //nrf |
DorijanMacek | 1:0f605b9eed83 | 36 | const int transfer_size = 4; |
DorijanMacek | 1:0f605b9eed83 | 37 | char txData[transfer_size],rxData[transfer_size]; |
DorijanMacek | 1:0f605b9eed83 | 38 | int txDataCnt = 0; |
DorijanMacek | 1:0f605b9eed83 | 39 | int rxDataCnt = 0; |
DorijanMacek | 1:0f605b9eed83 | 40 | |
DorijanMacek | 1:0f605b9eed83 | 41 | //joystick |
DorijanMacek | 1:0f605b9eed83 | 42 | float velocity=upDown; |
DorijanMacek | 1:0f605b9eed83 | 43 | float direction =leftRight; |
DorijanMacek | 1:0f605b9eed83 | 44 | |
DorijanMacek | 1:0f605b9eed83 | 45 | //MSP430g |
DorijanMacek | 1:0f605b9eed83 | 46 | const int addr= 0x94; |
DorijanMacek | 3:07d5ce3c32e3 | 47 | float temp=0.00; |
DorijanMacek | 3:07d5ce3c32e3 | 48 | float volt=0.00; |
DorijanMacek | 1:0f605b9eed83 | 49 | |
DorijanMacek | 1:0f605b9eed83 | 50 | int testT=0; |
DorijanMacek | 1:0f605b9eed83 | 51 | int testY=0; |
DorijanMacek | 1:0f605b9eed83 | 52 | |
DorijanMacek | 2:d0f85a573b89 | 53 | |
DorijanMacek | 0:d74d1d840f60 | 54 | int main() |
DorijanMacek | 0:d74d1d840f60 | 55 | { |
DorijanMacek | 1:0f605b9eed83 | 56 | |
DorijanMacek | 0:d74d1d840f60 | 57 | |
DorijanMacek | 0:d74d1d840f60 | 58 | |
DorijanMacek | 3:07d5ce3c32e3 | 59 | res=1; |
DorijanMacek | 0:d74d1d840f60 | 60 | startLCD(); |
DorijanMacek | 0:d74d1d840f60 | 61 | startNRF(transfer_size); |
DorijanMacek | 1:0f605b9eed83 | 62 | wait(1); |
DorijanMacek | 1:0f605b9eed83 | 63 | |
DorijanMacek | 2:d0f85a573b89 | 64 | Thread t0(readJoystick, (void *)"readJoystick"); |
DorijanMacek | 3:07d5ce3c32e3 | 65 | //Thread t1(readTempFromMSP430G, (void *)"readTemp"); |
DorijanMacek | 3:07d5ce3c32e3 | 66 | Thread t2(readVoltFromMSP430G, (void *)"readVoltage"); |
DorijanMacek | 2:d0f85a573b89 | 67 | Thread t3(printTempAndVoltOnLCD, (void *)"printTemp"); |
DorijanMacek | 2:d0f85a573b89 | 68 | Thread t4(printJoystickOnLCD, (void *)"printJoytick"); |
DorijanMacek | 1:0f605b9eed83 | 69 | |
DorijanMacek | 1:0f605b9eed83 | 70 | |
DorijanMacek | 1:0f605b9eed83 | 71 | |
DorijanMacek | 2:d0f85a573b89 | 72 | |
DorijanMacek | 1:0f605b9eed83 | 73 | //Thread t0(readJoystick, (void *)"readJoystick"); |
DorijanMacek | 1:0f605b9eed83 | 74 | //Thread t1(readTempFromMSP430G, (void *)"readTemp"); |
DorijanMacek | 1:0f605b9eed83 | 75 | //Thread t2(readVoltFromMSP430G, (void *)"readVoltage"); |
DorijanMacek | 1:0f605b9eed83 | 76 | //Thread t3(printTempAndVoltOnLCD, (void *)"printTemp"); |
DorijanMacek | 1:0f605b9eed83 | 77 | //Thread t4(printJoystickOnLCD, (void *)"printJoytick"); |
DorijanMacek | 1:0f605b9eed83 | 78 | |
DorijanMacek | 2:d0f85a573b89 | 79 | //printTempAndVoltOnLCD((void *)"printemAndVolt"); |
DorijanMacek | 2:d0f85a573b89 | 80 | //printJoystickOnLCD((void *)"printjoystick"); |
DorijanMacek | 2:d0f85a573b89 | 81 | //readJoystick((void *)"readJoystick"); |
DorijanMacek | 2:d0f85a573b89 | 82 | //readTempFromMSP430G((void *)"readTemp"); |
DorijanMacek | 0:d74d1d840f60 | 83 | |
DorijanMacek | 0:d74d1d840f60 | 84 | |
DorijanMacek | 1:0f605b9eed83 | 85 | //readVoltFromMSP430G((void *)"readVoltage"); |
DorijanMacek | 1:0f605b9eed83 | 86 | //Thread printOnLCD(temp,volt,1); |
DorijanMacek | 1:0f605b9eed83 | 87 | //Thread t2(test_thread, (void *)"Th 2"); |
DorijanMacek | 2:d0f85a573b89 | 88 | |
DorijanMacek | 2:d0f85a573b89 | 89 | while(1){} |
DorijanMacek | 1:0f605b9eed83 | 90 | |
DorijanMacek | 0:d74d1d840f60 | 91 | } |
DorijanMacek | 0:d74d1d840f60 | 92 | |
DorijanMacek | 0:d74d1d840f60 | 93 | void startLCD() |
DorijanMacek | 0:d74d1d840f60 | 94 | { |
DorijanMacek | 0:d74d1d840f60 | 95 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 96 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 97 | display.printf("Dorijan Macek"); // print on screen |
DorijanMacek | 0:d74d1d840f60 | 98 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 99 | display.printf("TVZ 2015 / 2016"); |
DorijanMacek | 0:d74d1d840f60 | 100 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 101 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 102 | display.printf("Dobro dosli "); |
DorijanMacek | 0:d74d1d840f60 | 103 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 104 | display.printf("................"); |
DorijanMacek | 0:d74d1d840f60 | 105 | wait(0.5); |
DorijanMacek | 0:d74d1d840f60 | 106 | } |
DorijanMacek | 0:d74d1d840f60 | 107 | void startNRF(int size) |
DorijanMacek | 0:d74d1d840f60 | 108 | { |
DorijanMacek | 0:d74d1d840f60 | 109 | odasiljac.setTransferSize( size); |
DorijanMacek | 0:d74d1d840f60 | 110 | odasiljac.setTransmitMode(); |
DorijanMacek | 0:d74d1d840f60 | 111 | odasiljac.enable(); |
DorijanMacek | 0:d74d1d840f60 | 112 | |
DorijanMacek | 0:d74d1d840f60 | 113 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 114 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 115 | display.printf( "Odasiljac "); |
DorijanMacek | 0:d74d1d840f60 | 116 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 117 | pc.printf( " "); |
DorijanMacek | 0:d74d1d840f60 | 118 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 119 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 120 | |
DorijanMacek | 0:d74d1d840f60 | 121 | display.printf( "Frequency : "); |
DorijanMacek | 0:d74d1d840f60 | 122 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 123 | display.printf ("%d MHz",odasiljac.getRfFrequency() ); |
DorijanMacek | 0:d74d1d840f60 | 124 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 125 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 126 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 127 | |
DorijanMacek | 0:d74d1d840f60 | 128 | display.printf( "Output power : "); |
DorijanMacek | 0:d74d1d840f60 | 129 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 130 | display.printf("%d dBm", odasiljac.getRfOutputPower() ); |
DorijanMacek | 0:d74d1d840f60 | 131 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 132 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 133 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 134 | |
DorijanMacek | 0:d74d1d840f60 | 135 | display.printf( "Data Rate : "); |
DorijanMacek | 0:d74d1d840f60 | 136 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 137 | display.printf("%d kbps", odasiljac.getAirDataRate() ); |
DorijanMacek | 0:d74d1d840f60 | 138 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 139 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 140 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 141 | |
DorijanMacek | 0:d74d1d840f60 | 142 | display.printf( "TX Address : "); |
DorijanMacek | 0:d74d1d840f60 | 143 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 144 | display.printf("0x%010llX", odasiljac.getTxAddress() ); |
DorijanMacek | 0:d74d1d840f60 | 145 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 146 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 147 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 148 | |
DorijanMacek | 0:d74d1d840f60 | 149 | display.printf( "RX Address : "); |
DorijanMacek | 0:d74d1d840f60 | 150 | display.SetXY(0,1); |
DorijanMacek | 0:d74d1d840f60 | 151 | display.printf("0x%010llX", odasiljac.getRxAddress() ); |
DorijanMacek | 0:d74d1d840f60 | 152 | wait(1); |
DorijanMacek | 0:d74d1d840f60 | 153 | display.Clear(); |
DorijanMacek | 0:d74d1d840f60 | 154 | display.SetXY(0,0); |
DorijanMacek | 0:d74d1d840f60 | 155 | |
DorijanMacek | 0:d74d1d840f60 | 156 | wait(0.5); |
DorijanMacek | 0:d74d1d840f60 | 157 | |
DorijanMacek | 1:0f605b9eed83 | 158 | } |
DorijanMacek | 1:0f605b9eed83 | 159 | |
DorijanMacek | 1:0f605b9eed83 | 160 | void printTempAndVoltOnLCD(void const *args) |
DorijanMacek | 1:0f605b9eed83 | 161 | { |
DorijanMacek | 2:d0f85a573b89 | 162 | while(true) |
DorijanMacek | 2:d0f85a573b89 | 163 | { |
DorijanMacek | 2:d0f85a573b89 | 164 | semLCD.wait(); |
DorijanMacek | 1:0f605b9eed83 | 165 | |
DorijanMacek | 1:0f605b9eed83 | 166 | int znakgore=30; |
DorijanMacek | 1:0f605b9eed83 | 167 | int znakdolje=31; |
DorijanMacek | 1:0f605b9eed83 | 168 | int znaklijevo=174; |
DorijanMacek | 1:0f605b9eed83 | 169 | int znakdesno=175; |
DorijanMacek | 1:0f605b9eed83 | 170 | |
DorijanMacek | 1:0f605b9eed83 | 171 | display.SetXY(8,0); |
DorijanMacek | 1:0f605b9eed83 | 172 | display.printf("T = %.2f ",temp); |
DorijanMacek | 1:0f605b9eed83 | 173 | display.SetXY(8,1); |
DorijanMacek | 1:0f605b9eed83 | 174 | display.printf("V = %.2f ",volt); |
DorijanMacek | 3:07d5ce3c32e3 | 175 | //pc.printf("printTempAndVoltOnLCD \n\r"); |
DorijanMacek | 1:0f605b9eed83 | 176 | |
DorijanMacek | 3:07d5ce3c32e3 | 177 | |
DorijanMacek | 3:07d5ce3c32e3 | 178 | Thread::wait(500); |
DorijanMacek | 1:0f605b9eed83 | 179 | semLCD.release(); |
DorijanMacek | 2:d0f85a573b89 | 180 | } |
DorijanMacek | 1:0f605b9eed83 | 181 | } |
DorijanMacek | 0:d74d1d840f60 | 182 | |
DorijanMacek | 1:0f605b9eed83 | 183 | void printJoystickOnLCD(void const *args) |
DorijanMacek | 0:d74d1d840f60 | 184 | { |
DorijanMacek | 2:d0f85a573b89 | 185 | while(true) |
DorijanMacek | 2:d0f85a573b89 | 186 | { |
DorijanMacek | 2:d0f85a573b89 | 187 | semLCD.wait(); |
DorijanMacek | 1:0f605b9eed83 | 188 | |
DorijanMacek | 1:0f605b9eed83 | 189 | display.SetXY(0,0); |
DorijanMacek | 1:0f605b9eed83 | 190 | display.printf("Up %.2f ",velocity); |
DorijanMacek | 1:0f605b9eed83 | 191 | display.SetXY(0,1); |
DorijanMacek | 1:0f605b9eed83 | 192 | display.printf("LR %.2f ",direction); |
DorijanMacek | 3:07d5ce3c32e3 | 193 | //pc.printf("printJoystickOnLCD \n\r "); |
DorijanMacek | 1:0f605b9eed83 | 194 | |
DorijanMacek | 1:0f605b9eed83 | 195 | |
DorijanMacek | 3:07d5ce3c32e3 | 196 | Thread::wait(500); |
DorijanMacek | 1:0f605b9eed83 | 197 | semLCD.release(); |
DorijanMacek | 2:d0f85a573b89 | 198 | } |
DorijanMacek | 1:0f605b9eed83 | 199 | } |
DorijanMacek | 1:0f605b9eed83 | 200 | |
DorijanMacek | 1:0f605b9eed83 | 201 | |
DorijanMacek | 1:0f605b9eed83 | 202 | |
DorijanMacek | 1:0f605b9eed83 | 203 | void readJoystick(void const *args) |
DorijanMacek | 1:0f605b9eed83 | 204 | { |
DorijanMacek | 2:d0f85a573b89 | 205 | while(true) |
DorijanMacek | 2:d0f85a573b89 | 206 | { |
DorijanMacek | 2:d0f85a573b89 | 207 | semJoystick.wait(); |
DorijanMacek | 1:0f605b9eed83 | 208 | |
DorijanMacek | 1:0f605b9eed83 | 209 | velocity=upDown; |
DorijanMacek | 1:0f605b9eed83 | 210 | direction =leftRight; |
DorijanMacek | 3:07d5ce3c32e3 | 211 | //pc.printf("readJoystick \n\r "); |
DorijanMacek | 1:0f605b9eed83 | 212 | |
DorijanMacek | 1:0f605b9eed83 | 213 | Thread::wait(50); |
DorijanMacek | 1:0f605b9eed83 | 214 | semJoystick.release(); |
DorijanMacek | 2:d0f85a573b89 | 215 | } |
DorijanMacek | 1:0f605b9eed83 | 216 | |
DorijanMacek | 0:d74d1d840f60 | 217 | } |
DorijanMacek | 0:d74d1d840f60 | 218 | |
DorijanMacek | 1:0f605b9eed83 | 219 | void readTempFromMSP430G(void const *args) |
DorijanMacek | 0:d74d1d840f60 | 220 | { |
DorijanMacek | 2:d0f85a573b89 | 221 | while(true) |
DorijanMacek | 2:d0f85a573b89 | 222 | { |
DorijanMacek | 2:d0f85a573b89 | 223 | semMSP430G.wait(); |
DorijanMacek | 3:07d5ce3c32e3 | 224 | //MSP430G.stop(); |
DorijanMacek | 3:07d5ce3c32e3 | 225 | //Thread::wait(500); |
DorijanMacek | 3:07d5ce3c32e3 | 226 | |
DorijanMacek | 3:07d5ce3c32e3 | 227 | //res=1; |
DorijanMacek | 1:0f605b9eed83 | 228 | char config_t[2]; // transmitt buffer |
DorijanMacek | 1:0f605b9eed83 | 229 | char value_read[2]; // read buffer |
DorijanMacek | 1:0f605b9eed83 | 230 | config_t[0] = 0xC0; //config slave to int temp |
DorijanMacek | 1:0f605b9eed83 | 231 | config_t[1] = 0x55; // config data byte1, BOut |
DorijanMacek | 3:07d5ce3c32e3 | 232 | //MSP430G.start(); |
DorijanMacek | 3:07d5ce3c32e3 | 233 | //Thread::wait(20); |
DorijanMacek | 3:07d5ce3c32e3 | 234 | |
DorijanMacek | 1:0f605b9eed83 | 235 | MSP430G.write(addr, config_t, 2); |
DorijanMacek | 3:07d5ce3c32e3 | 236 | Thread::wait(20); |
DorijanMacek | 3:07d5ce3c32e3 | 237 | //wait_us(20); |
DorijanMacek | 3:07d5ce3c32e3 | 238 | MSP430G.read(addr, value_read, 2); //read the two-byte temp data |
DorijanMacek | 3:07d5ce3c32e3 | 239 | temp = ((value_read[0]+value_read[1]*256)/10.0); |
DorijanMacek | 3:07d5ce3c32e3 | 240 | pc.printf("readTempFromMSP430G %f \n\r ",temp); |
DorijanMacek | 3:07d5ce3c32e3 | 241 | res=0; |
DorijanMacek | 3:07d5ce3c32e3 | 242 | Thread::wait(5); |
DorijanMacek | 3:07d5ce3c32e3 | 243 | res=1; |
DorijanMacek | 1:0f605b9eed83 | 244 | Thread::wait(500); |
DorijanMacek | 3:07d5ce3c32e3 | 245 | |
DorijanMacek | 3:07d5ce3c32e3 | 246 | //MSP430G.abort_transfer(); |
DorijanMacek | 3:07d5ce3c32e3 | 247 | //wait(0.5); |
DorijanMacek | 3:07d5ce3c32e3 | 248 | |
DorijanMacek | 3:07d5ce3c32e3 | 249 | |
DorijanMacek | 3:07d5ce3c32e3 | 250 | //config_t[0] = 0xC1; //config slave to int temp |
DorijanMacek | 3:07d5ce3c32e3 | 251 | //config_t[1] = 0xff; // config data byte1, BOut |
DorijanMacek | 3:07d5ce3c32e3 | 252 | |
DorijanMacek | 3:07d5ce3c32e3 | 253 | //MSP430G.write(addr, config_t, 2); |
DorijanMacek | 3:07d5ce3c32e3 | 254 | //Thread::wait(20); |
DorijanMacek | 3:07d5ce3c32e3 | 255 | //wait_us(20); |
DorijanMacek | 3:07d5ce3c32e3 | 256 | //MSP430G.read(addr, value_read, 2); //read the two-byte temp data |
DorijanMacek | 3:07d5ce3c32e3 | 257 | //volt = ((value_read[0]+value_read[1]*256)*(1.5/1024)); |
DorijanMacek | 3:07d5ce3c32e3 | 258 | //pc.printf("readVoltFromMSP430G \n\r %f",volt); |
DorijanMacek | 3:07d5ce3c32e3 | 259 | |
DorijanMacek | 3:07d5ce3c32e3 | 260 | Thread::wait(500); |
DorijanMacek | 3:07d5ce3c32e3 | 261 | |
DorijanMacek | 3:07d5ce3c32e3 | 262 | //wait(0.5); |
DorijanMacek | 3:07d5ce3c32e3 | 263 | |
DorijanMacek | 3:07d5ce3c32e3 | 264 | |
DorijanMacek | 3:07d5ce3c32e3 | 265 | |
DorijanMacek | 1:0f605b9eed83 | 266 | semMSP430G.release(); |
DorijanMacek | 2:d0f85a573b89 | 267 | } |
DorijanMacek | 0:d74d1d840f60 | 268 | } |
DorijanMacek | 0:d74d1d840f60 | 269 | |
DorijanMacek | 0:d74d1d840f60 | 270 | |
DorijanMacek | 1:0f605b9eed83 | 271 | void readVoltFromMSP430G(void const *args) |
DorijanMacek | 0:d74d1d840f60 | 272 | { |
DorijanMacek | 2:d0f85a573b89 | 273 | while(true) |
DorijanMacek | 2:d0f85a573b89 | 274 | { |
DorijanMacek | 2:d0f85a573b89 | 275 | semMSP430G.wait(); |
DorijanMacek | 3:07d5ce3c32e3 | 276 | //MSP430G.stop(); |
DorijanMacek | 1:0f605b9eed83 | 277 | |
DorijanMacek | 1:0f605b9eed83 | 278 | char config_t[2]; // transmitt buffer |
DorijanMacek | 1:0f605b9eed83 | 279 | char value_read[2]; // read buffer |
DorijanMacek | 1:0f605b9eed83 | 280 | config_t[0] = 0xC1; //config slave to int temp |
DorijanMacek | 3:07d5ce3c32e3 | 281 | config_t[1] = 0xff; // config data byte1, BOut |
DorijanMacek | 3:07d5ce3c32e3 | 282 | //MSP430G.start(); |
DorijanMacek | 3:07d5ce3c32e3 | 283 | |
DorijanMacek | 3:07d5ce3c32e3 | 284 | //Thread::wait(20); |
DorijanMacek | 3:07d5ce3c32e3 | 285 | |
DorijanMacek | 1:0f605b9eed83 | 286 | MSP430G.write(addr, config_t, 2); |
DorijanMacek | 3:07d5ce3c32e3 | 287 | //MSP430G.stop(); |
DorijanMacek | 3:07d5ce3c32e3 | 288 | Thread::wait(20); |
DorijanMacek | 3:07d5ce3c32e3 | 289 | |
DorijanMacek | 1:0f605b9eed83 | 290 | |
DorijanMacek | 1:0f605b9eed83 | 291 | MSP430G.read(addr, value_read, 2); //read the two-byte temp data |
DorijanMacek | 3:07d5ce3c32e3 | 292 | //Thread::wait(500); |
DorijanMacek | 3:07d5ce3c32e3 | 293 | |
DorijanMacek | 1:0f605b9eed83 | 294 | volt = (value_read[0]+value_read[1]*256)*(1.5/1024); |
DorijanMacek | 3:07d5ce3c32e3 | 295 | pc.printf("readVoltFromMSP430G \n\r %f",volt); |
DorijanMacek | 3:07d5ce3c32e3 | 296 | |
DorijanMacek | 3:07d5ce3c32e3 | 297 | //MSP430G.stop(); |
DorijanMacek | 3:07d5ce3c32e3 | 298 | res=0; |
DorijanMacek | 3:07d5ce3c32e3 | 299 | Thread::wait(5); |
DorijanMacek | 3:07d5ce3c32e3 | 300 | res=1; |
DorijanMacek | 1:0f605b9eed83 | 301 | Thread::wait(500); |
DorijanMacek | 3:07d5ce3c32e3 | 302 | |
DorijanMacek | 3:07d5ce3c32e3 | 303 | //MSP430G.stop(); |
DorijanMacek | 1:0f605b9eed83 | 304 | semMSP430G.release(); |
DorijanMacek | 2:d0f85a573b89 | 305 | } |
DorijanMacek | 3:07d5ce3c32e3 | 306 | } |
DorijanMacek | 3:07d5ce3c32e3 | 307 | |
DorijanMacek | 3:07d5ce3c32e3 | 308 |