SSCI824 I2C Test Don't work.

Dependencies:   mbed

http://developer.mbed.org/questions/5761/I2C-Problem/

Files at this revision

API Documentation at this revision

Comitter:
mark8018
Date:
Sun Dec 28 08:18:55 2014 +0000
Commit message:
created.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 56fa72db2898 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Dec 28 08:18:55 2014 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+
+#if defined (TARGET_MBED_LPC1768)
+// Defines for sensors I2C
+#define SDA     p9
+#define SCL     p10
+
+#elif defined (TARGET_SSCI824)
+// Defines for sensors I2C
+#define SDA     dp4
+#define SCL     dp5
+
+#elif defined (TARGET_LPC11U35_401)
+// Defines for sensors I2C
+#define SDA     P0_5
+#define SCL     P0_4
+
+#else
+#error "Unknown target type"
+#endif
+
+#define I2C_ADDRES (0x1c<<1)
+Serial pc(USBTX, USBRX);
+I2C i2c(SDA, SCL);
+char temp[6];
+
+int main()
+{
+    pc.baud(115200);
+
+    wait(1.0);
+
+    memset(temp, 0, sizeof(temp));
+    temp[0]=0x0D; // REG_WHO_AM_I
+    if(i2c.write(I2C_ADDRES, temp, 1, true) != 0) pc.printf("I2C write error\r\n");
+    memset(temp, 0, sizeof(temp));
+    if(i2c.read(I2C_ADDRES, temp, 1, false) != 0) pc.printf("I2C read error\r\n");
+    pc.printf("ID is %X\r\n",(int)temp[0]); // ID is 0x1A
+
+    memset(temp, 0, sizeof(temp));
+    temp[0]=0x2A; // REG_CTRL_REG1
+    temp[1]=0x19; // Data
+    if(i2c.write(I2C_ADDRES, temp, 2, false) != 0) pc.printf("I2C write error\r\n");
+
+    while(1) {}
+}
diff -r 000000000000 -r 56fa72db2898 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 28 08:18:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file