![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
gen master public
Fork of freemaster3_1 by
main.cpp
- Committer:
- viswachaitanya
- Date:
- 2014-12-05
- Revision:
- 0:cdc20d6056de
File content as of revision 0:cdc20d6056de:
#include "mbed.h" const int addr = 0x20; //slave address I2C master (D14,D15); //configure pins p27,p28 as I2C master Serial pc (USBTX,USBRX); void main() { printf("press backspace for master to start \n\r"); while(1){ if(pc.getc()==8){ bool master_status_write = true; bool master_status_read = true; char* data_send = new char; *data_send = 'b'; char *data_rec = new char; *data_rec = 'b'; bool write_loop = true; bool read_loop = true; while(write_loop){ printf("2 master clk freq setup and addressing slave\n\r"); master.frequency(100000); //set clock frequency master.start(); //initiating the data transfer master_status_write = (bool) master.write(addr|0x00,data_send,1); if(!master_status_write){ printf("3 master has written %c to slave\n\r",*data_send); write_loop=false; } } printf("done\n\r"); while(read_loop){ printf("4 master clk freq setup and addressing slave\n\r"); master.frequency(100000); //set clock frequency master.start(); //initiating the data transfer master_status_read = (bool) master.read(addr,data_rec,1); if(!master_status_read){ printf("5 master has read %c from slave\n\r",*data_rec); read_loop=false; } } printf("done\n\r"); } } }