![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
i2c stand alone working
Fork of slave_working_obama by
main.cpp@1:4c71a7675750, 2014-12-08 (annotated)
- Committer:
- raizel_varun
- Date:
- Mon Dec 08 03:55:57 2014 +0000
- Revision:
- 1:4c71a7675750
- Parent:
- 0:24e80ff2c7b1
- Child:
- 2:458f9e603814
slave3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
viswachaitanya | 0:24e80ff2c7b1 | 1 | #include "mbed.h" |
viswachaitanya | 0:24e80ff2c7b1 | 2 | |
viswachaitanya | 0:24e80ff2c7b1 | 3 | void write_to_master(char); //function to write data to master |
viswachaitanya | 0:24e80ff2c7b1 | 4 | |
viswachaitanya | 0:24e80ff2c7b1 | 5 | I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave |
viswachaitanya | 0:24e80ff2c7b1 | 6 | Serial pc (USBTX,USBRX); |
viswachaitanya | 0:24e80ff2c7b1 | 7 | |
viswachaitanya | 0:24e80ff2c7b1 | 8 | void main(){ |
viswachaitanya | 0:24e80ff2c7b1 | 9 | printf("press backspace for slave to start \n\r"); |
raizel_varun | 1:4c71a7675750 | 10 | char *data_send = new char; |
raizel_varun | 1:4c71a7675750 | 11 | *data_send = 'k'; |
viswachaitanya | 0:24e80ff2c7b1 | 12 | while(1){ |
raizel_varun | 1:4c71a7675750 | 13 | //if(pc.getc()==8){ |
raizel_varun | 1:4c71a7675750 | 14 | // bool loopvariable1= true; |
raizel_varun | 1:4c71a7675750 | 15 | |
viswachaitanya | 0:24e80ff2c7b1 | 16 | slave.address(0x20); |
viswachaitanya | 0:24e80ff2c7b1 | 17 | int slave_status=1; |
raizel_varun | 1:4c71a7675750 | 18 | //while(loopvariable1){ |
viswachaitanya | 0:24e80ff2c7b1 | 19 | if(slave.receive()==1){ |
viswachaitanya | 0:24e80ff2c7b1 | 20 | slave_status=slave.write(data_send,1); |
viswachaitanya | 0:24e80ff2c7b1 | 21 | if(!slave_status){ |
viswachaitanya | 0:24e80ff2c7b1 | 22 | printf("1 wrote %c to master\n\r",*data_send); |
raizel_varun | 1:4c71a7675750 | 23 | // loopvariable1 = false; |
viswachaitanya | 0:24e80ff2c7b1 | 24 | } |
viswachaitanya | 0:24e80ff2c7b1 | 25 | } |
viswachaitanya | 0:24e80ff2c7b1 | 26 | } |
viswachaitanya | 0:24e80ff2c7b1 | 27 | printf("2 done"); |
viswachaitanya | 0:24e80ff2c7b1 | 28 | } |
raizel_varun | 1:4c71a7675750 | 29 | |
raizel_varun | 1:4c71a7675750 | 30 |