Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of master_sample by
main.cpp
- Committer:
- raizel_varun
- Date:
- 2014-12-06
- Revision:
- 1:d4903940ac9b
- Parent:
- 0:b2ba86a47999
- Child:
- 2:385ef26be324
File content as of revision 1:d4903940ac9b:
#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;
if(pc.getc()=='a'){
printf("\n backspace 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");
}}
}
