Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of freeslave2_1 by
Diff: main.cpp
- Revision:
- 3:5e68dd4bbb70
- Parent:
- 2:458f9e603814
- Child:
- 4:133b49d51b18
--- a/main.cpp Tue Dec 09 12:35:12 2014 +0000 +++ b/main.cpp Wed Dec 10 05:21:50 2014 +0000 @@ -5,7 +5,7 @@ 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) +void FUNC_I2C_WRITE2CDMS(char * data,int length) { int slave_status = 1; @@ -14,23 +14,31 @@ slave.address(0x20); if(slave.receive()==1) { - slave_status=slave.write(data_send,length); - printf("\n In the while loop\n"); + slave_status=slave.write(data,length); + // printf("\n In the while loop\n"); - if(!slave_status) + /* if(!slave_status) { - printf("slave wrote %c to master\n\r",*data_send); + 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() +/*void FUNC_I2C_READFCDMS() { printf("\nEntered slave code\n"); @@ -55,19 +63,20 @@ delete data_rec; } - +*/ void main() { printf("\nStarted slave... waiting for master\n"); - char * data_send = new char; - *data_send = 'a'; + char * data = new char; + *data = 'a'; while(1) { //*(data_send)=pc.getc(); - FUNC_I2C_READFCDMS(); - (*data_send)++; + FUNC_I2C_WRITE2CDMS(data,1); + printf("\n The data send or received by slave is %c\n",*data); + (*data)++; //wait(1); } } \ No newline at end of file