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.
Diff: main.cpp
- Revision:
- 0:545d40142697
- Child:
- 1:5ed5d1e46e92
diff -r 000000000000 -r 545d40142697 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 06 13:01:02 2014 +0000 @@ -0,0 +1,34 @@ +#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 write_loop =1; + bool master_status_write = true; + while(write_loop){ + master.frequency(100000); //set clock frequency + master.start(); //initiating the data transfer + master_status_write = (bool) master.write(addr|0x00,command,1); + if(!master_status_write){ + printf("command %c sent to slave\n\r",*command); + write_loop=false; + } + } + delete command; + } +} \ No newline at end of file