i2c slave working version 1.0

Dependencies:   mbed-rtos mbed

Fork of freeslave_write2master_working by Seeker of Truth ,

Committer:
viswachaitanya
Date:
Sat Dec 06 06:24:28 2014 +0000
Revision:
0:24e80ff2c7b1
Child:
1:4c71a7675750
m_r_s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
viswachaitanya 0:24e80ff2c7b1 1 #include "mbed.h"
viswachaitanya 0:24e80ff2c7b1 2
viswachaitanya 0:24e80ff2c7b1 3 void write_to_master(char); //function to write data to master
viswachaitanya 0:24e80ff2c7b1 4
viswachaitanya 0:24e80ff2c7b1 5 I2CSlave slave(D14,D15); //configuring pins p27, p28 as I2Cslave
viswachaitanya 0:24e80ff2c7b1 6 Serial pc (USBTX,USBRX);
viswachaitanya 0:24e80ff2c7b1 7
viswachaitanya 0:24e80ff2c7b1 8 void main(){
viswachaitanya 0:24e80ff2c7b1 9 printf("press backspace for slave to start \n\r");
viswachaitanya 0:24e80ff2c7b1 10 while(1){
viswachaitanya 0:24e80ff2c7b1 11 if(pc.getc()==8){
viswachaitanya 0:24e80ff2c7b1 12 bool loopvariable1= true;
viswachaitanya 0:24e80ff2c7b1 13 char *data_send = new char;
viswachaitanya 0:24e80ff2c7b1 14 *data_send = 'k';
viswachaitanya 0:24e80ff2c7b1 15 slave.address(0x20);
viswachaitanya 0:24e80ff2c7b1 16 int slave_status=1;
viswachaitanya 0:24e80ff2c7b1 17 while(loopvariable1){
viswachaitanya 0:24e80ff2c7b1 18 if(slave.receive()==1){
viswachaitanya 0:24e80ff2c7b1 19 slave_status=slave.write(data_send,1);
viswachaitanya 0:24e80ff2c7b1 20 if(!slave_status){
viswachaitanya 0:24e80ff2c7b1 21 printf("1 wrote %c to master\n\r",*data_send);
viswachaitanya 0:24e80ff2c7b1 22 loopvariable1 = false;
viswachaitanya 0:24e80ff2c7b1 23 }
viswachaitanya 0:24e80ff2c7b1 24 }
viswachaitanya 0:24e80ff2c7b1 25 }
viswachaitanya 0:24e80ff2c7b1 26 printf("2 done");
viswachaitanya 0:24e80ff2c7b1 27 }
viswachaitanya 0:24e80ff2c7b1 28 }
viswachaitanya 0:24e80ff2c7b1 29 }