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 446STM32_Print_PC_I2CS by
Revision 3:4d977dd77a4b, committed 2017-11-10
- Comitter:
- Tanakacool
- Date:
- Fri Nov 10 05:08:18 2017 +0000
- Parent:
- 2:764981c589b6
- Commit message:
- v2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 764981c589b6 -r 4d977dd77a4b main.cpp --- a/main.cpp Mon Nov 06 08:23:22 2017 +0000 +++ b/main.cpp Fri Nov 10 05:08:18 2017 +0000 @@ -3,21 +3,28 @@ DigitalOut myled(LED1); Serial pc(USBTX, USBRX); I2CSlave slave(PC_9, PA_8); +void boxslave(); int main() { char buffer[128]; - char all_buf[]="i'm here!"; - char buf[20]; - char msg[] = "Hi Master!"; - slave.address(0xA0); + slave.address(0xA0); while(1){ + boxslave(); + if(pc.readable()) { - slave.stop(); + //slave.stop(); pc.gets(buffer, 128); pc.printf("I got '%s'\n", buffer); + //slave.stop(); } - int i = slave.receive(); + } +} +void boxslave(){ + char buf[20]; + char msg[] = "Hi Master!"; + char all_buf[]="i'm here!"; + int i = slave.receive(); switch (i) { case I2CSlave::ReadAddressed: if(!slave.write(msg, strlen(msg) + 1)) // Includes null char @@ -32,12 +39,10 @@ break; case I2CSlave::WriteAddressed: slave.read(buf, 20); - //slave.stop(); printf("master write to A: %s\n", buf); break; } for(int i = 0; i < 10; i++) { buf[i] = 0; // Clear buffer } - } } \ No newline at end of file