i2c master with interrupt

Dependencies:   mbed

Fork of freemaster2_1 by Seeker of Truth ,

Committer:
raizel_varun
Date:
Mon Dec 08 03:54:47 2014 +0000
Revision:
1:8e4b5e1f8039
Parent:
0:9ea68477caaf
Child:
2:2dd5bd9a64fb
master 3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
viswachaitanya 0:9ea68477caaf 1 #include "mbed.h"
viswachaitanya 0:9ea68477caaf 2
viswachaitanya 0:9ea68477caaf 3 const int addr = 0x20; //slave address
viswachaitanya 0:9ea68477caaf 4 I2C master (D14,D15); //configure pins p27,p28 as I2C master
viswachaitanya 0:9ea68477caaf 5 Serial pc (USBTX,USBRX);
viswachaitanya 0:9ea68477caaf 6
viswachaitanya 0:9ea68477caaf 7 void main()
viswachaitanya 0:9ea68477caaf 8 {
viswachaitanya 0:9ea68477caaf 9 printf("press backspace for master to start \n\r");
viswachaitanya 0:9ea68477caaf 10 while(1){
viswachaitanya 0:9ea68477caaf 11 if(pc.getc()==8){
viswachaitanya 0:9ea68477caaf 12 bool ack0 =true;
viswachaitanya 0:9ea68477caaf 13 char *data = new char;
viswachaitanya 0:9ea68477caaf 14 *data = 'b';
viswachaitanya 0:9ea68477caaf 15 bool loopvariable0 = true;
raizel_varun 1:8e4b5e1f8039 16 master.frequency(100000); //set clock frequency
raizel_varun 1:8e4b5e1f8039 17 //master.start();
raizel_varun 1:8e4b5e1f8039 18 while(ack0){
raizel_varun 1:8e4b5e1f8039 19 //printf("2 master clk freq setup and addressing slave\n\r");
raizel_varun 1:8e4b5e1f8039 20
viswachaitanya 0:9ea68477caaf 21 master.start(); //initiating the data transfer
raizel_varun 1:8e4b5e1f8039 22 ack0 = (bool) master.read(addr,data,1);}
viswachaitanya 0:9ea68477caaf 23 if(!ack0){
viswachaitanya 0:9ea68477caaf 24 printf("3 master has read %c from slave\n\r",*data);
viswachaitanya 0:9ea68477caaf 25 loopvariable0=false;
viswachaitanya 0:9ea68477caaf 26 }
viswachaitanya 0:9ea68477caaf 27 }
viswachaitanya 0:9ea68477caaf 28 printf("done\n\r");
viswachaitanya 0:9ea68477caaf 29 }
viswachaitanya 0:9ea68477caaf 30 }
raizel_varun 1:8e4b5e1f8039 31