sakthi priya amirtharaj
/
slave_working1_1
i2c slave working version 1.1
Fork of slave_i2c3 by
main.cpp
- Committer:
- greenroshks
- Date:
- 2014-12-09
- Revision:
- 2:458f9e603814
- Parent:
- 1:4c71a7675750
- Child:
- 3:5e68dd4bbb70
File content as of revision 2:458f9e603814:
#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_send,int length) { int slave_status = 1; while(slave_status) { slave.address(0x20); if(slave.receive()==1) { slave_status=slave.write(data_send,length); printf("\n In the while loop\n"); if(!slave_status) { printf("slave wrote %c to master\n\r",*data_send); } } //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_send = new char; *data_send = 'a'; while(1) { //*(data_send)=pc.getc(); FUNC_I2C_READFCDMS(); (*data_send)++; //wait(1); } }