Seeker of Truth , / Mbed 2 deprecated master_1

Dependencies:   mbed

Fork of master_1 by sakthi priya amirtharaj

main.cpp

Committer:
raizel_varun
Date:
2014-12-08
Revision:
2:39b25e32f00a
Parent:
1:5ed5d1e46e92

File content as of revision 2:39b25e32f00a:

#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* command= new char;
        char array[10];
        strcpy(array,"green");
        
    while(1)
    {    bool write_loop = true;
     
         printf("\ncommand from com \n\r");
         m2s_interrupt=0;
         *command=pc.getc();                //characters 0 to 4 are assumed to be commands
         printf("\n command detected\n\r");
         m2s_interrupt =1; 
         bool master_status_write = true;
         master.frequency(100000);
          
         while(write_loop ){                    
                 printf("2 master clk freq setup and addressing slave\n\r");
                master.start();                                 //initiating the data transfer
                master_status_write = (bool) master.write(addr|0x00,command,6);
                if(master_status_write==0){
                    printf("3 master has written %c to slave\n\r",*command);
                    write_loop=false;
                }
         printf("command %c sent to slave\n\r",*command);
         //delete command;
    }
}}