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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:d9fc59e03646
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Nov 03 19:43:07 2015 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+
+I2C i2c(I2C_SDA, I2C_SCL);
+
+int main()
+{
+ int address = 0x52;
+ char data[2];
+ char switch_word;
+ switch_word=0xa0;
+ char recd_val;
+
+i2c.frequency(400);
+ while(1) {
+ switch_word=switch_word|0x01;
+ i2c.start();
+//force a start condition
+ i2c.write(address);
+//send the address
+ i2c.write(switch_word);
+//send one byte of data, ie switch_word
+ i2c.stop();
+ wait(0.002);
+//receive a single byte of data, in correct I2C package
+ i2c.start();
+ i2c.write(address|0x01);
+//send address, with R/W bit set to Read
+ recd_val=i2c.read(address);
+//Read and save the received byte
+ i2c.stop();
+
+ printf("ACK: %d\n\r",recd_val);
+
+ }
+}
\ No newline at end of file