Compiler Error 849

  1. include "mbed.h"
  2. include "MMA8451Q.h"
  3. include "eeprom.h"
  1. define EEPROM_CONTROL_BYTE 0xA0
  2. define I2C_READ 0x01
  1. include "WakeUp.h"
  2. define OFF 1
  3. define ON 0 DigitalOut led2(LED_GREEN); DigitalOut pb(PTC8);

void wakeirq(void) { led2 = ON; wait(0.2); led2 = OFF; }

  1. if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) PinName const SDA = PTE25; PinName const SCL = PTE24;
  1. else
  2. error TARGET NOT DEFINED
  3. endif
  1. define MMA8451_I2C_ADDRESS (0x1d<<1)

EEPROM i2c(PTE0, PTE1, 0, EEPROM::T24C32); sda, scl on KL25Z Serial pc(USBTX, USBRX); tx, rx

int n; char data;

char offset= 0; char mac[6];

int main(void) { MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); PwmOut rled(LED1); PwmOut gled(LED2); PwmOut bled(LED3);

printf("MMA8451 ID: %d\n", acc.getWhoAmI());

WakeUp::calibrate(); WakeUp::attach(wakeirq); WakeUp::set(10); led2 = OFF; turn off the leds printf("\n\nStart\n");

int RomAddress=0x00;

while (true) { float x, y, z; x = rled = 1.0 - abs(acc.getAccX()); y = gled = 1.0 - abs(acc.getAccY()); z = bled = 1.0 - abs(acc.getAccZ()); wait(0.1); printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z);

i2c.write(RomAddress,x); wait_ms(1); RomAddress=RomAddress+4; 4 x 8 bit bytes used for 32bit float value

i2c.write(RomAddress,y); wait_ms(1); RomAddress=RomAddress+4;

i2c.write(RomAddress,z); wait_ms(1);

RomAddress = RomAddress - 8; rewind to begining of current Accel' read

i2c.read(RomAddress,x); RomAddress=RomAddress+4; i2c.read(RomAddress,y); RomAddress=RomAddress+4; i2c.read(RomAddress,z);

pc.printf("Address %04d romX: %1.5f romY: %1.5f romZ: %1.5f Error %d \r\r\n", RomAddress -8, x, y, z, i2c.getError());

RomAddress = RomAddress + 4; forward to next free rom address

offset = 0xFA; if (i2c.write(EEPROM_CONTROL_BYTE, &offset, 1) != 0) { printf("Failed to write to I2C device (%x) at offset 0xFA\n", EEPROM_CONTROL_BYTE); break; } if (i2c.read(EEPROM_CONTROL_BYTE, mac, 6) != 0) { printf("Failed to read from I2C device (%x) at offset 0xFA\n", EEPROM_CONTROL_BYTE); } pc.printf ("EEPROM Mac address is .. %02x:%02x:%02x:%02x:%02x:%02x \r\n",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5] );

pb = 1; printf("Entering sleep.\n"); deepsleep(); WakeUp::set(10); wake up in 10 seconds pb = 0; } }


All wikipages