Seeker of Truth , / Mbed 2 deprecated master_sample

Dependencies:   mbed-rtos mbed

Fork of master_sample by sakthi priya amirtharaj

main.cpp

Committer:
raizel_varun
Date:
2014-12-07
Revision:
2:385ef26be324
Parent:
1:d4903940ac9b
Child:
3:583585376a2d

File content as of revision 2:385ef26be324:

#include "mbed.h"

#define interrupt D9

const int addr = 0x20;                     //slave address 
I2C master (D14,D15);                      //configure pins p27,p28 as I2C master
Serial pc(USBTX,USBRX);
DigitalOut m2s_interrupt(interrupt);



int main()
{   
    
    char* data_send =  new char;
    *data_send = 'b';
     char *data_rec =  new char;
    *data_rec = 'b';
    bool master_status_write = true;
    master.start();
    master_status_write = (bool) master.write(addr|0x00,data_send,1);
    bool write_loop;
    //m2s_interrupt=0;
    while(1){
      write_loop = true;
     //printf("m2s_interrupt is 0");
     printf("\npress a for master to start \n\r");
     m2s_interrupt=0;
     *data_send=pc.getc();
    //if(pc.getc()=='a'){
            printf("\ncommand detected\n\r");
            m2s_interrupt =1;          //hardware interrupt from master to slave  
           // wait(10);         
             master_status_write = true;
            //bool master_status_read = 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==0){
                    printf("3 master has written %c to slave\n\r",*data_send);
                    write_loop=false;
                }
            }
            
            printf("done\n\r");
        }
}