I2C debug program for use with RealTerm. Sends I2C commands to P9 and P10. Run program on mbed. Start RealTerm, select the mbed virtual com port under the port tab, then open RealTerm's I2C command tab. Reset mbed. See http://mbed.org/users/4180_1/notebook/i2c-debug-for-realterm/ for instructions
Revision 2:fa8c916b42a9, committed 2011-03-14
- Comitter:
- 4180_1
- Date:
- Mon Mar 14 00:50:34 2011 +0000
- Parent:
- 1:be1498ba7fb4
- Commit message:
- ver3
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r be1498ba7fb4 -r fa8c916b42a9 main.cpp --- a/main.cpp Fri Mar 11 03:25:42 2011 +0000 +++ b/main.cpp Mon Mar 14 00:50:34 2011 +0000 @@ -15,6 +15,7 @@ int main() { char last_command=0; + char previous_command=0; char current_char=0; char address=0; char data [255]; @@ -31,15 +32,20 @@ i2c.frequency(75000); i2c.start(); i2c.stop(); + // Send a start message to RealTerm + pc.printf("\fmbed I2C debug tool ready\n\r"); + // Scan for I2C devices that reply with ack + for (i=0; i<=254; i=i+2) { + if (i2c.read(i, &data[0], 1) ==0) printf("I2C device detected at address=%2.2X\n\r", i); + } + data[0]=0; i2c.start(); i2c.stop(); -// Send a start message to RealTerm - pc.printf("\fmbed I2C debug tool ready\n\r"); // Loop processing command strings from RealTerm while (1) { current_char = pc.getc(); // Is it a two character ASCII string data byte value - if (current_char <='F') { + if ((current_char <='F') && (current_char !='?')) { // convert to a binary byte if (current_char <='9') current_byte = current_char - '0'; else current_byte =current_char +10 -'A'; @@ -69,6 +75,7 @@ switch (last_command) { // Start case 'S': + if (previous_command == 'S') i2c.start(); first_data_byte=1; break; // Stop @@ -106,9 +113,10 @@ break; // Unknown or unimplemented command default: - pc.printf("unknown command"); + pc.printf(" unknown command \n\r"); break; } + previous_command = last_command; } } } \ No newline at end of file