![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
while loop removed ( master to slave not working )
Fork of master_working_obama by
Diff: main.cpp
- Revision:
- 7:0d18080e16ce
- Parent:
- 6:efcbb48e0d03
--- a/main.cpp Sat Jan 24 11:48:32 2015 +0000 +++ b/main.cpp Mon Jan 26 11:11:59 2015 +0000 @@ -7,7 +7,7 @@ DigitalOut interrupt(D9); InterruptIn data_ready(D10); Timer t; - +Timer t2; int reset; typedef struct @@ -31,9 +31,10 @@ //while(1){ //interrupt = 0; // if(pc.getc()=='z'){ - wait(0.2); + interrupt = 1; + t2.start(); //printf("\nMaster executed\n"); @@ -66,8 +67,13 @@ //{ //printf("\n\r %x \n",addr); - //initiating the data transfer + //t2.stop(); //initiating the data transfer + //wait_ms(10); + ack0 = master.read(addr|1,data,length); + t2.stop(); + //t2.stop(); + //printf("\nready to receive\n"); //} @@ -79,7 +85,8 @@ loopvariable0=false; } //master.stop(); - + printf("\n%d\n\r",t2.read_us()); + t2.reset(); //printf("done\n\r"); //delete data; interrupt=0; @@ -119,32 +126,37 @@ interrupt = 0; char data = pc.getc(); + i2c_data * i2c_data_s = i2c_data_send.alloc(); i2c_data_s->data = data; i2c_data_s->length = 1; i2c_data_send.put(i2c_data_s); bool master_status_write = true; interrupt = 1; - + t.start(); + //wait_ms(43); //to account for npt entering the inteupt = 1 conditin on slave due to the interruitp = 0 above osEvent evt = i2c_data_send.get(); if (evt.status == osEventMail) { i2c_data *i2c_data_s = (i2c_data*)evt.value.p; *writedata = i2c_data_s -> data; //master.frequency(100000); //set clock frequency - if(interrupt ==1) - { + //while(write2slave) + //{ printf("\nhere\n"); - //master.start(); //initiating the data transfer + //master.start(); + t.stop(); //initiating the data transfer master_status_write = (bool) master.write(addr|0x00,writedata,1); if(master_status_write==0) { printf("master has written %c to slave\n\r",*writedata); write2slave=false; } + printf("\n%f\n",t.read()); + t.reset(); i2c_data_send.free(i2c_data_s); //printf("\n \r %d %d %d %d %d\n",*data_reg,*status_reg,*c1_reg,*c2_reg,*freq_reg); - } + //} } }