![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
slave reading from master
main.cpp@0:4add0b6d656a, 2014-12-06 (annotated)
- Committer:
- viswachaitanya
- Date:
- Sat Dec 06 06:21:10 2014 +0000
- Revision:
- 0:4add0b6d656a
m_w_s
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
viswachaitanya | 0:4add0b6d656a | 1 | #include "mbed.h" |
viswachaitanya | 0:4add0b6d656a | 2 | |
viswachaitanya | 0:4add0b6d656a | 3 | void write_to_master(char); //function to write data to master |
viswachaitanya | 0:4add0b6d656a | 4 | |
viswachaitanya | 0:4add0b6d656a | 5 | I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave |
viswachaitanya | 0:4add0b6d656a | 6 | Serial pc (USBTX,USBRX); |
viswachaitanya | 0:4add0b6d656a | 7 | |
viswachaitanya | 0:4add0b6d656a | 8 | void main(){ |
viswachaitanya | 0:4add0b6d656a | 9 | printf("press backspace for slave to start \n\r"); |
viswachaitanya | 0:4add0b6d656a | 10 | while(1){ |
viswachaitanya | 0:4add0b6d656a | 11 | if(pc.getc()==8){ |
viswachaitanya | 0:4add0b6d656a | 12 | bool loopvariable1= true; |
viswachaitanya | 0:4add0b6d656a | 13 | char *data_rec = new char; |
viswachaitanya | 0:4add0b6d656a | 14 | slave.address(0x20); |
viswachaitanya | 0:4add0b6d656a | 15 | int slave_status=1; |
viswachaitanya | 0:4add0b6d656a | 16 | while(loopvariable1){ |
viswachaitanya | 0:4add0b6d656a | 17 | slave_status=slave.read(data_rec,1); |
viswachaitanya | 0:4add0b6d656a | 18 | if(!slave_status){ |
viswachaitanya | 0:4add0b6d656a | 19 | printf("read %c from master\n\r",*data_rec); |
viswachaitanya | 0:4add0b6d656a | 20 | loopvariable1 = false; |
viswachaitanya | 0:4add0b6d656a | 21 | } |
viswachaitanya | 0:4add0b6d656a | 22 | } |
viswachaitanya | 0:4add0b6d656a | 23 | } |
viswachaitanya | 0:4add0b6d656a | 24 | } |
viswachaitanya | 0:4add0b6d656a | 25 | } |