sakthi priya amirtharaj / Mbed 2 deprecated master_1

Dependencies:   mbed

main.cpp

Committer:
sakthipriya
Date:
2014-12-07
Revision:
1:5ed5d1e46e92
Parent:
0:545d40142697

File content as of revision 1:5ed5d1e46e92:

#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()
{
    while(1)
    {
         char* command= new char;
         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(master_status_write)
         {
                master.start(); 
                master_status_write = (bool) master.write(addr|0x00,command,1);
                printf("\n master trying to write \n\r");
         }
         printf("command %c sent to slave\n\r",*command);
         delete command;
    }
}