pay d
Dependencies: mbed-rtos mbed-src mbed
Fork of I2C_HelloWorld_Mbed by
Diff: main.cpp
- Revision:
- 1:e42651c601d2
- Parent:
- 0:f76c26307f9a
--- a/main.cpp Thu Feb 14 17:24:48 2013 +0000 +++ b/main.cpp Sat Jun 13 11:13:00 2015 +0000 @@ -1,25 +1,70 @@ #include "mbed.h" - -// Read temperature from LM75BD +#include "rtos.h" -I2C i2c(p28, p27); +const int addr = 0x20<<1; //slave address +I2C master (D14,D15); //configure pins p27,p28 as I2C master +Serial pc (USBTX,USBRX); +//DigitalOut interrupt(D9); +//InterruptIn data_ready(D10); +InterruptIn aple(D11); -const int addr = 0x90; +DigitalOut pes(D12); +DigitalOut led(LED_RED); +DigitalOut led1(LED_GREEN); + + -int main() { - char cmd[2]; - while (1) { - cmd[0] = 0x01; - cmd[1] = 0x00; - i2c.write(addr, cmd, 2); +bool f = 1; +char rdata; +void readds() +{ //wait(); + led = ! led ; + f = master.read(addr,&rdata,1); + if(f == 0) led1 = ! led1 ; + //pc.printf("read %d \n",rdata); + + } + + int loop=1; + char *writedata = new char; +void FUNC_MASTER_WRITE() + { int data = pc.getc(); + loop=1; - wait(0.5); - - cmd[0] = 0x00; - i2c.write(addr, cmd, 1); - i2c.read(addr, cmd, 2); - - float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0); - printf("Temp = %.2f\n", tmp); + pc.printf("read "); + master.frequency(100000); + *writedata = data; + while(loop) + { + bool check = (bool)master.write(addr,writedata,1); + //pc.printf("read "); + if(check==0) + { + pc.printf("written\n"); + loop=0; + //readds(); + + } + + } +} +int main() +{ + + //data_ready.rise(&FUNC_INT); + printf("\nstarted master\n"); + // aple.mode(PullDown); + aple.rise(&readds); + //aple.rise(&readds); + while(1) + + { + pc.printf("read %d \n",rdata); + //pes = 1; + //wait(5); + //pes = 0; + //wait(5); + // if(aple==1)led=!led; + //FUNC_MASTER_WRITE(); } } \ No newline at end of file