![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
while loop removed ( master cant send)
Fork of slave_working_obama by
main.cpp
- Committer:
- greenroshks
- Date:
- 2014-12-10
- Revision:
- 3:5e68dd4bbb70
- Parent:
- 2:458f9e603814
- Child:
- 4:133b49d51b18
File content as of revision 3:5e68dd4bbb70:
#include "mbed.h" void write_to_master(char); //function to write data to master I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave Serial pc (USBTX,USBRX); InterruptIn interrupt(D9); void FUNC_I2C_WRITE2CDMS(char * data,int length) { int slave_status = 1; while(slave_status) { slave.address(0x20); if(slave.receive()==1) { slave_status=slave.write(data,length); // printf("\n In the while loop\n"); /* if(!slave_status) { printf("slave wrote %c to master\n\r",*data); }*/ } else if(slave.receive()==3 || slave.receive()==2) { slave_status=slave.read(data,length); /*if(!slave_status) { printf("1 read %c from master\n\r",*data); }*/ } //slave.stop(); } printf("2 done"); } /*void FUNC_I2C_READFCDMS() { printf("\nEntered slave code\n"); //read_loop=true; char *data_rec = new char; int slave_status =1; slave.address(0x20); printf("\nentered slave while loop\n"); //if(slave.receive()==3) while(slave_status==1) slave_status=slave.read(data_rec,1); if(slave_status==0){printf("1 read %c from master\n\r",*data_rec);} // read_loop = false;} printf("\n done \n \r"); delete data_rec; } */ void main() { printf("\nStarted slave... waiting for master\n"); char * data = new char; *data = 'a'; while(1) { //*(data_send)=pc.getc(); FUNC_I2C_WRITE2CDMS(data,1); printf("\n The data send or received by slave is %c\n",*data); (*data)++; //wait(1); } }