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:
- 2:458f9e603814
- Parent:
- 1:4c71a7675750
- Child:
- 3:5e68dd4bbb70
--- a/main.cpp Mon Dec 08 03:55:57 2014 +0000 +++ b/main.cpp Tue Dec 09 12:35:12 2014 +0000 @@ -4,27 +4,70 @@ 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 main(){ - printf("press backspace for slave to start \n\r"); - char *data_send = new char; - *data_send = 'k'; - while(1){ - //if(pc.getc()==8){ - // bool loopvariable1= true; - + int slave_status = 1; + while(slave_status) + { slave.address(0x20); - int slave_status=1; - //while(loopvariable1){ - if(slave.receive()==1){ - slave_status=slave.write(data_send,1); - if(!slave_status){ - printf("1 wrote %c to master\n\r",*data_send); - // loopvariable1 = false; - } + 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; - \ No newline at end of file +} + +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); + } +} \ No newline at end of file