![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
hkdata send using string working
Fork of greenisthemaster by
Diff: main.cpp
- Revision:
- 3:e1dc841fca6d
- Parent:
- 2:e80af3c366aa
- Child:
- 4:cf8d2c7b65ad
--- a/main.cpp Mon Dec 15 05:51:25 2014 +0000 +++ b/main.cpp Tue Dec 16 07:43:16 2014 +0000 @@ -11,7 +11,7 @@ typedef struct { - char data; // To avoid dynamic memory allocation + char data[13]; // To avoid dynamic memory allocation int length; }i2c_data; @@ -64,7 +64,7 @@ } if(!ack0) { - printf("\n master has read %c from slave\n\r",*data); + printf("\n master has read %s from slave\n\r",data); loopvariable0=false; } //master.stop(); @@ -76,16 +76,16 @@ void T_I2C_MASTER_FSLAVE(void const *args) { - char data_receive; + char data_receive[13]; while(1) { Thread::signal_wait(0x1); - FUNC_I2C_MASTER_FSLAVE(&data_receive,1); + FUNC_I2C_MASTER_FSLAVE(data_receive,13); i2c_data * i2c_data_r = i2c_data_receive.alloc(); - i2c_data_r->data = data_receive; - i2c_data_r->length = 1; + strcpy(i2c_data_r->data , data_receive); + i2c_data_r->length = 13; i2c_data_receive.put(i2c_data_r); - printf("\n Data received from slave is %c\n\r",data_receive); + printf("\n Data received from slave is %s\n\r",data_receive); i2c_data_receive.free(i2c_data_r); } } @@ -97,17 +97,17 @@ } -char *writedata = new char; +char writedata[13]; void FUNC_MASTER_WRITE() { bool write2slave=true; interrupt = 0; - char data = pc.getc(); + char data[13]="shakti priya"; i2c_data * i2c_data_s = i2c_data_send.alloc(); - i2c_data_s->data = data; - i2c_data_s->length = 1; + strcpy(i2c_data_s->data ,data); + i2c_data_s->length = 13; i2c_data_send.put(i2c_data_s); bool master_status_write = true; interrupt = 1; @@ -115,16 +115,16 @@ if (evt.status == osEventMail) { i2c_data *i2c_data_s = (i2c_data*)evt.value.p; - *writedata = i2c_data_s -> data; + strcpy(writedata ,i2c_data_s -> data); master.frequency(100000); //set clock frequency while(write2slave) { 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); + master_status_write = (bool) master.write(addr|0x00,writedata,13); if(master_status_write==0) { - printf("master has written %c to slave\n\r",*writedata); + printf("master has written %s to slave\n\r",writedata); write2slave=false; } i2c_data_send.free(i2c_data_s); @@ -141,7 +141,8 @@ printf("\nstarted master\n"); while(1) { - FUNC_MASTER_WRITE(); - + //Thread::wait(10000); + // FUNC_MASTER_WRITE(); + ; } } \ No newline at end of file