Sergeh Vartanian
/
End_Device
WSN End Device
Fork of I2C_HelloWorld_Mbed by
main.cpp@1:bc4ec3bf209e, 2014-06-16 (annotated)
- Committer:
- LAvtec818
- Date:
- Mon Jun 16 18:23:01 2014 +0000
- Revision:
- 1:bc4ec3bf209e
- Parent:
- 0:f76c26307f9a
End Device
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:f76c26307f9a | 1 | #include "mbed.h" |
LAvtec818 | 1:bc4ec3bf209e | 2 | #include "PowerControl.h" |
LAvtec818 | 1:bc4ec3bf209e | 3 | #include "EthernetPowerControl.h" |
mbed_official | 0:f76c26307f9a | 4 | |
mbed_official | 0:f76c26307f9a | 5 | // Read temperature from LM75BD |
LAvtec818 | 1:bc4ec3bf209e | 6 | #define USR_POWERDOWN (0x104) |
mbed_official | 0:f76c26307f9a | 7 | |
mbed_official | 0:f76c26307f9a | 8 | I2C i2c(p28, p27); |
LAvtec818 | 1:bc4ec3bf209e | 9 | Serial pc(USBTX, USBRX); // tx, rx |
LAvtec818 | 1:bc4ec3bf209e | 10 | InterruptIn PIR_in(p5); |
LAvtec818 | 1:bc4ec3bf209e | 11 | Serial xbee1(p9,p10); |
LAvtec818 | 1:bc4ec3bf209e | 12 | DigitalOut rst1(p11); |
mbed_official | 0:f76c26307f9a | 13 | |
LAvtec818 | 1:bc4ec3bf209e | 14 | Timer t; |
LAvtec818 | 1:bc4ec3bf209e | 15 | |
LAvtec818 | 1:bc4ec3bf209e | 16 | //Ticker flipper; |
LAvtec818 | 1:bc4ec3bf209e | 17 | |
LAvtec818 | 1:bc4ec3bf209e | 18 | const int tx_addr = 0x14; |
LAvtec818 | 1:bc4ec3bf209e | 19 | const int rx_addr = 0x15; |
LAvtec818 | 1:bc4ec3bf209e | 20 | char readbuff [35]; |
LAvtec818 | 1:bc4ec3bf209e | 21 | char tx_cmd[1]; |
LAvtec818 | 1:bc4ec3bf209e | 22 | |
LAvtec818 | 1:bc4ec3bf209e | 23 | void flip() { |
LAvtec818 | 1:bc4ec3bf209e | 24 | char c = 'z'; |
LAvtec818 | 1:bc4ec3bf209e | 25 | tx_cmd[0] = 0x4C; |
LAvtec818 | 1:bc4ec3bf209e | 26 | //tx_cmd[1] = 0x4C; |
LAvtec818 | 1:bc4ec3bf209e | 27 | //i2c.write(tx_addr, |
LAvtec818 | 1:bc4ec3bf209e | 28 | i2c.write(tx_addr, tx_cmd , 1); |
LAvtec818 | 1:bc4ec3bf209e | 29 | |
LAvtec818 | 1:bc4ec3bf209e | 30 | wait(0.25); |
LAvtec818 | 1:bc4ec3bf209e | 31 | |
LAvtec818 | 1:bc4ec3bf209e | 32 | //i2c.write(rx_addr, cmd, 1); |
LAvtec818 | 1:bc4ec3bf209e | 33 | i2c.read(rx_addr, readbuff, 35); |
LAvtec818 | 1:bc4ec3bf209e | 34 | |
LAvtec818 | 1:bc4ec3bf209e | 35 | //float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); |
LAvtec818 | 1:bc4ec3bf209e | 36 | int x = 256*readbuff[1] + readbuff [0]; |
LAvtec818 | 1:bc4ec3bf209e | 37 | |
LAvtec818 | 1:bc4ec3bf209e | 38 | //xbee1.printf("%d\t%d\t%d\t%d\n\r%d\t%d\t%d\t%d\n\r%d\t%d\t%d\t%d\n\r%d\t%d\t%d\t%d\n\r\n\r",x1,x2,x3, |
LAvtec818 | 1:bc4ec3bf209e | 39 | //x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16); |
LAvtec818 | 1:bc4ec3bf209e | 40 | for (int i = 2; i < 34; i++) |
LAvtec818 | 1:bc4ec3bf209e | 41 | xbee1.putc(readbuff[i]); |
LAvtec818 | 1:bc4ec3bf209e | 42 | |
LAvtec818 | 1:bc4ec3bf209e | 43 | int x17 = readbuff[34]; |
LAvtec818 | 1:bc4ec3bf209e | 44 | } |
mbed_official | 0:f76c26307f9a | 45 | |
mbed_official | 0:f76c26307f9a | 46 | int main() { |
LAvtec818 | 1:bc4ec3bf209e | 47 | |
LAvtec818 | 1:bc4ec3bf209e | 48 | |
LAvtec818 | 1:bc4ec3bf209e | 49 | i2c.frequency(50000); |
LAvtec818 | 1:bc4ec3bf209e | 50 | xbee1.baud(115200); |
LAvtec818 | 1:bc4ec3bf209e | 51 | |
LAvtec818 | 1:bc4ec3bf209e | 52 | PHY_PowerDown(); |
LAvtec818 | 1:bc4ec3bf209e | 53 | |
LAvtec818 | 1:bc4ec3bf209e | 54 | |
LAvtec818 | 1:bc4ec3bf209e | 55 | //PHY_PowerDown(); |
LAvtec818 | 1:bc4ec3bf209e | 56 | rst1 = 0; //Set reset pin to 0 |
LAvtec818 | 1:bc4ec3bf209e | 57 | wait_ms(1);//Wait at least one millisecond |
LAvtec818 | 1:bc4ec3bf209e | 58 | rst1 = 1;//Set reset pin to 1 |
LAvtec818 | 1:bc4ec3bf209e | 59 | wait_ms(1); |
LAvtec818 | 1:bc4ec3bf209e | 60 | |
LAvtec818 | 1:bc4ec3bf209e | 61 | wait_ms(75000) ; // wait for 1 minute for initial start up |
LAvtec818 | 1:bc4ec3bf209e | 62 | |
LAvtec818 | 1:bc4ec3bf209e | 63 | PIR_in.rise(&flip); |
LAvtec818 | 1:bc4ec3bf209e | 64 | PIR_in.fall(&flip); |
LAvtec818 | 1:bc4ec3bf209e | 65 | |
LAvtec818 | 1:bc4ec3bf209e | 66 | /* if ((xbee1.readable()){ |
LAvtec818 | 1:bc4ec3bf209e | 67 | if ('y' == xbee1.getc()) |
LAvtec818 | 1:bc4ec3bf209e | 68 | break; |
LAvtec818 | 1:bc4ec3bf209e | 69 | else |
LAvtec818 | 1:bc4ec3bf209e | 70 | sleep(); |
LAvtec818 | 1:bc4ec3bf209e | 71 | }*/ |
LAvtec818 | 1:bc4ec3bf209e | 72 | |
mbed_official | 0:f76c26307f9a | 73 | while (1) { |
LAvtec818 | 1:bc4ec3bf209e | 74 | |
LAvtec818 | 1:bc4ec3bf209e | 75 | sleep(); |
LAvtec818 | 1:bc4ec3bf209e | 76 | // pc.printf("system on idle\n\r"); |
LAvtec818 | 1:bc4ec3bf209e | 77 | //pc.printf("x1 = %d\n",x1); |
mbed_official | 0:f76c26307f9a | 78 | } |
mbed_official | 0:f76c26307f9a | 79 | } |