with Starboard Orange
Freescale MMA7660FC accelometer with Startboard Orange.
Please visit http://bird.dip.jp/mt/archives/2012/05/31/2240.html
Revision 2:4679f396cfdd, committed 2013-03-19
- Comitter:
- masato
- Date:
- Tue Mar 19 12:40:17 2013 +0000
- Parent:
- 1:dc5d150d4fa6
- Commit message:
- Freescale MMA7660 and Startboard Orange
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 dc5d150d4fa6 -r 4679f396cfdd main.cpp --- a/main.cpp Fri Jul 13 02:18:47 2012 +0000 +++ b/main.cpp Tue Mar 19 12:40:17 2013 +0000 @@ -3,7 +3,6 @@ TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 -#define I2C_MULTI_RW 0 #define USE_INTR 1 I2C i2c(p9, p10); // sda, scl @@ -31,47 +30,27 @@ void i2c_write(int addr, char *p, int n) { int i, r; -#if I2C_MULTI_RW - r = i2c.write(addr, p, n); - // pc.printf("%s(%02x) for write(i2c_write addr)\r\n", r? "NAK": "ACK", r); -#else + i2c.start(); r = i2c.write(addr << 1); // write mode - // pc.printf("%s(%02x) for write(i2c_write addr)\r\n", r? "ACK": "NAK", r); for (i = 0; i < n; i++) { r = i2c.write((int)*p++); - // pc.printf("%s(%02x) for write(i2c_write data) %d\r\n", r? "ACK": "NAK", r, i); } i2c.stop(); // wait(0.1); -#endif } int i2c_read(int addr, int reg) { int r; -#if I2C_MULTI_RW - char d[2]; - d[0] = reg; - r = i2c.write(addr, d, 1, 1); // do not send stop - pc.printf("%s(%02x) for write(i2c_read set reg)\r\n", r? "NAK": "ACK", r); - i2c.start(); - r = i2c.read(addr, d, 1); - pc.printf("%s(%02x) for write(i2c_read read)\r\n", r? "NAK": "ACK", r); - return d[0]; -#else + i2c.start(); r = i2c.write(addr << 1); // set read bit - // pc.printf("%s(%02x) for write(i2c_read addr)\r\n", r? "ACK": "NAK", r); r = i2c.write(reg); - // pc.printf("%s(%02x) for write(i2c_read reg)\r\n", r? "ACK": "NAK", r); i2c.start(); r = i2c.write((addr << 1) | 1); // set read bit - // pc.printf("%s(%02x) for write(i2c_read addr 2)\r\n", r? "ACK": "NAK", r); r = i2c.read(0); // read the data with nack i2c.stop(); - // wait(0.1); return r; -#endif } void configureMMA7760() { @@ -83,16 +62,10 @@ cmd[0] = MODE; cmd[1] = 0x00; i2c_write(MMA7660, cmd, 2); // Standby Modes cmd[0] = SPCNT; cmd[1] = 0x00; i2c_write(MMA7660, cmd, 2); // No sleep count cmd[0] = INTSU; cmd[1] = 0x03; i2c_write(MMA7660, cmd, 2); // Configure GINT Interrupt - // cmd[0] = INTSU; cmd[1] = 0xE0; i2c_write(MMA7660, cmd, 2); // Configure Shake Interrupt cmd[0] = PDET; cmd[1] = 0xE0; i2c_write(MMA7660, cmd, 2); // No tap detection enabled cmd[0] = SR; cmd[1] = 0x34; i2c_write(MMA7660, cmd, 2); // 8 samples/s, TILT debounce filter = 2 - // cmd[0] = SR; cmd[1] = 0x02; i2c_write(MMA7660, cmd, 2); // 32 samples/s, debounce count enables cmd[0] = PD; cmd[1] = 0x00; i2c_write(MMA7660, cmd, 2); // No tap detection debounce count enabled cmd[0] = MODE; cmd[1] = 0x41; i2c_write(MMA7660, cmd, 2); // No tap detection debounce count enabled - // pc.printf("READY\r\n") ; - - // r = i2c_read(MMA7660, MODE); - // pc.printf("MODE: %02x\r\n", r); } int se(int r) {
diff -r dc5d150d4fa6 -r 4679f396cfdd mbed.bld --- a/mbed.bld Fri Jul 13 02:18:47 2012 +0000 +++ b/mbed.bld Tue Mar 19 12:40:17 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6 \ No newline at end of file