![](/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:
- 6:efcbb48e0d03
- Parent:
- 5:cb35b461fa29
- Child:
- 7:0d18080e16ce
--- a/main.cpp Thu Jan 22 14:34:49 2015 +0000 +++ b/main.cpp Sat Jan 24 11:48:32 2015 +0000 @@ -6,6 +6,7 @@ Serial pc (USBTX,USBRX); DigitalOut interrupt(D9); InterruptIn data_ready(D10); +Timer t; int reset; @@ -30,9 +31,10 @@ //while(1){ //interrupt = 0; // if(pc.getc()=='z'){ - wait(0.5); + wait(0.2); + interrupt = 1; - printf("\nMaster executed\n"); + //printf("\nMaster executed\n"); bool ack0 =true; @@ -43,7 +45,7 @@ // master.frequency(100000); //set clock frequency - master.start(); + // master.start(); /*while(write2slave) { *writedata = pc.getc(); wait(0.5); @@ -60,15 +62,15 @@ }*/ //wait(0.5); - while(ack0 ) - { + //while(ack0 ) + //{ //printf("\n\r %x \n",addr); //initiating the data transfer ack0 = master.read(addr|1,data,length); //printf("\nready to receive\n"); - } + //} if(!ack0 ) { @@ -81,6 +83,9 @@ //printf("done\n\r"); //delete data; interrupt=0; + + + } void T_I2C_MASTER_FSLAVE(void const *args) @@ -119,16 +124,17 @@ i2c_data_s->length = 1; i2c_data_send.put(i2c_data_s); bool master_status_write = true; - interrupt = 1; + interrupt = 1; + 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 - while(write2slave && interrupt ==1) + if(interrupt ==1) { - printf("master clk freq setup and addressing slave\n\r"); + printf("\nhere\n"); //master.start(); //initiating the data transfer master_status_write = (bool) master.write(addr|0x00,writedata,1); if(master_status_write==0) @@ -146,9 +152,12 @@ int main() { + int i= 0; + //master.start(); master.frequency(100000); ptr_t_i2c = new Thread(T_I2C_MASTER_FSLAVE); + data_ready.rise(&FUNC_INT); printf("\nstarted master\n"); //master.start();