![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
i2c while removed working
Fork of CDMS_tc2 by
Diff: main.cpp
- Revision:
- 3:6c1ed31073f0
- Parent:
- 2:c75bb488d17c
--- a/main.cpp Sat Dec 20 06:23:00 2014 +0000 +++ b/main.cpp Sat Jan 31 14:14:01 2015 +0000 @@ -8,6 +8,10 @@ InterruptIn data_ready(D10); int reset; +Timer t; +Timer t1; +Timer t2; +Timer t3; typedef struct { @@ -21,58 +25,28 @@ Thread * ptr_t_i2c; void FUNC_I2C_MASTER_FSLAVE(char * data,int length) { - //printf("press backspace for master to start \n\r"); - //while(1){ - //interrupt = 0; - // if(pc.getc()=='z'){ - //wait(0.5); - interrupt = 1; - printf("\nMaster executed\n"); + - bool ack0 =true; - bool loopvariable0 =true; - //char *data = new char; - //*data = 'b'; - - - master.frequency(100000); //set clock frequency - //master.start(); - /*while(write2slave) - { *writedata = pc.getc(); - wait(0.5); - - printf("master clk freq setup and addressing slave\n\r"); - master.start(); //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; - } - - - }*/ - - while(ack0 && data_ready ==1 ) - { - //printf("2 master clk freq setup and addressing slave\n\r"); - - master.start(); //initiating the data transfer - ack0 = master.read(addr,data,length); - } + interrupt = 1; + t1.start(); + //wait_ms(20); + ack0 = master.read(addr|1,data,length); + t1.stop(); + + if(!ack0) { printf("\n master has read %s from slave\n\r",data); - loopvariable0=false; + } //master.stop(); + printf("\n%d\n\r",t1.read_us()); + t1.reset(); - //printf("done\n\r"); - //delete data; interrupt=0; - printf("\n blahblah\n\r"); + } typedef struct { @@ -91,7 +65,7 @@ } hk_data; hk_data decode_data; -void TC_DECODE(char *data_hk) //getting the structure back from hk data sent by bae +/*void TC_DECODE(char *data_hk) //getting the structure back from hk data sent by bae { for(int i=0;i<=7;i++) { @@ -127,7 +101,7 @@ printf("\n voltage %s\n\r",decode_data.Voltage); printf("\n current %s\n\r",decode_data.Current); printf("\n faultpoll %c\n\r",decode_data.faultpoll); -} +}*/ void T_I2C_MASTER_FSLAVE(void const *args) @@ -144,7 +118,7 @@ i2c_data_r->length = 25; i2c_data_receive.put(i2c_data_r);*/ printf("\n Data received from slave is %s\n\r",data_receive); - TC_DECODE(data_receive); + //TC_DECODE(data_receive); } } @@ -166,6 +140,9 @@ char data = pc.getc(); interrupt = 1; + t.start(); + t3.start(); + wait_ms(20); i2c_data * i2c_data_s = i2c_data_send.alloc(); i2c_data_s->data = data; i2c_data_s->length = 1; @@ -179,21 +156,22 @@ { 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 ) - { - printf("master clk freq setup and addressing slave\n\r"); - master.start(); //initiating the data transfer + t.stop(); + //t3.start(); master_status_write = (bool) master.write(addr|0x00,&writedata,1); + t3.stop(); if(master_status_write==0) { printf("master has written %c to slave\n\r",writedata); write2slave=false; } i2c_data_send.free(i2c_data_s); - } + printf("\n%d\n",t.read_us()); + t.reset(); + printf("\n%d\n",t3.read_us()); + t3.reset(); } - interrupt = 0; + interrupt = 0; } @@ -204,6 +182,7 @@ ptr_t_i2c = new Thread(T_I2C_MASTER_FSLAVE); data_ready.rise(&FUNC_INT); printf("\nstarted master\n"); + master.frequency(100000); while(1) { //Thread::wait(9000); //interrupt = 1;