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@1:5ed5d1e46e92, 2014-12-07 (annotated)
- Committer:
- sakthipriya
- Date:
- Sun Dec 07 07:39:35 2014 +0000
- Revision:
- 1:5ed5d1e46e92
- Parent:
- 0:545d40142697
commands using switch case
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 master_status_write = true; |
sakthipriya | 1:5ed5d1e46e92 | 22 | master.frequency(100000); |
sakthipriya | 1:5ed5d1e46e92 | 23 | while(master_status_write) |
sakthipriya | 1:5ed5d1e46e92 | 24 | { |
sakthipriya | 1:5ed5d1e46e92 | 25 | master.start(); |
sakthipriya | 0:545d40142697 | 26 | master_status_write = (bool) master.write(addr|0x00,command,1); |
sakthipriya | 1:5ed5d1e46e92 | 27 | printf("\n master trying to write \n\r"); |
sakthipriya | 1:5ed5d1e46e92 | 28 | } |
sakthipriya | 1:5ed5d1e46e92 | 29 | printf("command %c sent to slave\n\r",*command); |
sakthipriya | 1:5ed5d1e46e92 | 30 | delete command; |
sakthipriya | 0:545d40142697 | 31 | } |
sakthipriya | 0:545d40142697 | 32 | } |