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_1 by
main.cpp@2:39b25e32f00a, 2014-12-08 (annotated)
- Committer:
- raizel_varun
- Date:
- Mon Dec 08 03:56:44 2014 +0000
- Revision:
- 2:39b25e32f00a
- Parent:
- 1:5ed5d1e46e92
sdfc
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 | { |
raizel_varun | 2:39b25e32f00a | 13 | char* command= new char; |
raizel_varun | 2:39b25e32f00a | 14 | char array[10]; |
raizel_varun | 2:39b25e32f00a | 15 | strcpy(array,"green"); |
raizel_varun | 2:39b25e32f00a | 16 | |
sakthipriya | 0:545d40142697 | 17 | while(1) |
raizel_varun | 2:39b25e32f00a | 18 | { bool write_loop = true; |
raizel_varun | 2:39b25e32f00a | 19 | |
sakthipriya | 0:545d40142697 | 20 | printf("\ncommand from com \n\r"); |
sakthipriya | 0:545d40142697 | 21 | m2s_interrupt=0; |
sakthipriya | 0:545d40142697 | 22 | *command=pc.getc(); //characters 0 to 4 are assumed to be commands |
sakthipriya | 0:545d40142697 | 23 | printf("\n command detected\n\r"); |
sakthipriya | 0:545d40142697 | 24 | m2s_interrupt =1; |
sakthipriya | 0:545d40142697 | 25 | bool master_status_write = true; |
raizel_varun | 2:39b25e32f00a | 26 | master.frequency(100000); |
raizel_varun | 2:39b25e32f00a | 27 | |
raizel_varun | 2:39b25e32f00a | 28 | while(write_loop ){ |
raizel_varun | 2:39b25e32f00a | 29 | printf("2 master clk freq setup and addressing slave\n\r"); |
raizel_varun | 2:39b25e32f00a | 30 | master.start(); //initiating the data transfer |
raizel_varun | 2:39b25e32f00a | 31 | master_status_write = (bool) master.write(addr|0x00,command,6); |
raizel_varun | 2:39b25e32f00a | 32 | if(master_status_write==0){ |
raizel_varun | 2:39b25e32f00a | 33 | printf("3 master has written %c to slave\n\r",*command); |
raizel_varun | 2:39b25e32f00a | 34 | write_loop=false; |
raizel_varun | 2:39b25e32f00a | 35 | } |
sakthipriya | 1:5ed5d1e46e92 | 36 | printf("command %c sent to slave\n\r",*command); |
raizel_varun | 2:39b25e32f00a | 37 | //delete command; |
sakthipriya | 0:545d40142697 | 38 | } |
raizel_varun | 2:39b25e32f00a | 39 | }} |