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.
main.cpp@0:545d40142697, 2014-12-06 (annotated)
- Committer:
- sakthipriya
- Date:
- Sat Dec 06 13:01:02 2014 +0000
- Revision:
- 0:545d40142697
- Child:
- 1:5ed5d1e46e92
master_1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sakthipriya | 0:545d40142697 | 1 | #include "mbed.h" |
sakthipriya | 0:545d40142697 | 2 | |
sakthipriya | 0:545d40142697 | 3 | #define interrupt D9 |
sakthipriya | 0:545d40142697 | 4 | |
sakthipriya | 0:545d40142697 | 5 | const int addr = 0x20; //slave address |
sakthipriya | 0:545d40142697 | 6 | I2C master (D14,D15); //configure pins p27,p28 as I2C master |
sakthipriya | 0:545d40142697 | 7 | Serial pc(USBTX,USBRX); |
sakthipriya | 0:545d40142697 | 8 | DigitalOut m2s_interrupt(interrupt); |
sakthipriya | 0:545d40142697 | 9 | |
sakthipriya | 0:545d40142697 | 10 | |
sakthipriya | 0:545d40142697 | 11 | int main() |
sakthipriya | 0:545d40142697 | 12 | { |
sakthipriya | 0:545d40142697 | 13 | while(1) |
sakthipriya | 0:545d40142697 | 14 | { |
sakthipriya | 0:545d40142697 | 15 | char* command= new char; |
sakthipriya | 0:545d40142697 | 16 | printf("\ncommand from com \n\r"); |
sakthipriya | 0:545d40142697 | 17 | m2s_interrupt=0; |
sakthipriya | 0:545d40142697 | 18 | *command=pc.getc(); //characters 0 to 4 are assumed to be commands |
sakthipriya | 0:545d40142697 | 19 | printf("\n command detected\n\r"); |
sakthipriya | 0:545d40142697 | 20 | m2s_interrupt =1; |
sakthipriya | 0:545d40142697 | 21 | bool write_loop =1; |
sakthipriya | 0:545d40142697 | 22 | bool master_status_write = true; |
sakthipriya | 0:545d40142697 | 23 | while(write_loop){ |
sakthipriya | 0:545d40142697 | 24 | master.frequency(100000); //set clock frequency |
sakthipriya | 0:545d40142697 | 25 | master.start(); //initiating the data transfer |
sakthipriya | 0:545d40142697 | 26 | master_status_write = (bool) master.write(addr|0x00,command,1); |
sakthipriya | 0:545d40142697 | 27 | if(!master_status_write){ |
sakthipriya | 0:545d40142697 | 28 | printf("command %c sent to slave\n\r",*command); |
sakthipriya | 0:545d40142697 | 29 | write_loop=false; |
sakthipriya | 0:545d40142697 | 30 | } |
sakthipriya | 0:545d40142697 | 31 | } |
sakthipriya | 0:545d40142697 | 32 | delete command; |
sakthipriya | 0:545d40142697 | 33 | } |
sakthipriya | 0:545d40142697 | 34 | } |