green rosh / Mbed 2 deprecated freemaster_write2master_working

Dependencies:   mbed

Fork of freemaster2_1 by Seeker of Truth ,

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 const int addr = 0x20;                     //slave address 
00004 I2C master (D14,D15);                      //configure pins p27,p28 as I2C master
00005 Serial pc (USBTX,USBRX);
00006 DigitalOut interrupt(D9);
00007 InterruptIn data_ready(D10);
00008 void FUNC_I2C_MASTER()
00009 {
00010     //printf("press backspace for master to start \n\r");
00011     //while(1){
00012       //  interrupt = 0;
00013       //  if(pc.getc()=='z'){
00014             interrupt = 1;
00015             printf("\nEntered master function\n");
00016             int ack0 =true; 
00017             char *data =  new char;
00018             *data = 'b';
00019             bool loopvariable0 = true;
00020              master.frequency(100000);                       //set clock frequency
00021              //master.start();
00022             while(ack0)
00023             {
00024                 //printf("2 master clk freq setup and addressing slave\n\r");
00025                 
00026                 master.start();                                 //initiating the data transfer
00027                 ack0 =  master.read(addr,data,1);
00028             }
00029             if(!ack0)
00030             {
00031                     printf("\n master has read %c from slave\n\r",*data);
00032                     loopvariable0=false;
00033             }
00034                 //master.stop();
00035             
00036             //printf("done\n\r");
00037             delete data;
00038             interrupt=0;
00039 }
00040 void main()
00041 {
00042     data_ready.rise(&FUNC_I2C_MASTER);
00043     printf("\nstarted master\n");
00044     while(1)
00045     {
00046         ;
00047     }
00048 }