Chaitanya Viswa
/
freeslave5_1
funtions sorted
Revision 0:21ffb42911bd, committed 2014-12-08
- Comitter:
- viswachaitanya
- Date:
- Mon Dec 08 12:36:07 2014 +0000
- Commit message:
- write and read functions sorted
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 21ffb42911bd main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Dec 08 12:36:07 2014 +0000 @@ -0,0 +1,60 @@ +#include "mbed.h" + +char* read_from_master(); //function to write data to master +int write_to_master(char*,int); + +I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave +Serial pc (USBTX,USBRX); + +bool read_loop = true; +bool write_loop = true; +char *data_rec = new char; +char *data_send = new char; +char *rec_data = new char; +int slave_status = 1; +int k; + + +int main(){ + + slave.address(0x20); + while(1){ + slave.stop(); + printf("11 press any character for slave to start \n\r"); + *data_send = pc.getc(); + + printf("1 in main\n\r"); + k = write_to_master(data_send,1); + printf("4 done transfer with return %d\n\r",k); + } + +} + + +char* read_from_master(){ + + while(slave_status) + slave_status=slave.read(data_rec,1); + + return(data_rec); + + + //read_loop = true; + //slave.stop(); + +} + +int write_to_master(char* send, int length){ + slave_status=1; + while(slave_status){ + printf("2 wait for status\n\r"); + //if(slave.receive()==1) + { + slave_status=slave.write(send,length); + } + } + printf("3 wrote %c to master\n\r",*data_send); + + //slave.stop(); + return(1); +} \ No newline at end of file
diff -r 000000000000 -r 21ffb42911bd mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Dec 08 12:36:07 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file