/* ** =================================================================== ** Method : MAG1_GetXYZ8 (component MAG3110) ** Description : ** Returns in an array the x, y and z sensor values as 8bit ** values. Note that for this method the FAST_READ flag *shall* ** be set. ** Parameters : ** NAME - DESCRIPTION ** * xyz - Pointer to an array of three signed 8bit ** values which are used to return the ** accelerometer values. ** Returns : ** --- - Error code, ERR_OK for no error. ** =================================================================== */ uint8_t MAG1_GetXYZ8(signed char *xyz) { /* NOTE: this function assumes that FAST_READ *is* set, as it reads 3 bytes */ static const uint8_t addr = MAG1_OUT_X_MSB; return GI2C1_ReadAddress(MAG1_I2C_ADDR, (uint8_t*)&addr, sizeof(addr), (uint8_t*)xyz, 3); }
/** * Gets the X, Y and Z values of the accelerometer in the KL25Z board and * sends the data to the UART peripheral if debug mode is active. *************************************************************************** */ void accelerometer_readXYZ(void) { uint8 registerRead = MMA8451_OUT_X_MSB; int8 xyz[3] = {0, 1, 2}; GI2C1_ReadAddress(MMA8451_I2C_ADDRESS, ®isterRead, 1, (uint8_t*)&xyz, 3); #ifdef DEBUGFLAG uart_SendString("X: "); uart_SendByte(xyz[0]); uart_SendString("; Y: "); uart_SendByte(xyz[1]); uart_SendString("; Z: "); uart_SendByte(xyz[2]); uart_SendStringLn(";"); #endif }
/* ** =================================================================== ** Method : MAG1_GetZ (component MAG3110) ** Description : ** Returns the Z magnetometer value. ** Parameters : ** NAME - DESCRIPTION ** * value - Pointer to where to store the value ** Returns : ** --- - Error code ** =================================================================== */ byte MAG1_GetZ(int16_t *value) { union { uint8_t buf[2]; /* value from device is in big endian */ int16_t be; } val; static const uint8_t addr = MAG1_OUT_Z_MSB; if (GI2C1_ReadAddress(MAG1_I2C_ADDR, (uint8_t*)&addr, sizeof(addr), &val.buf[0], sizeof(val.buf))!=ERR_OK) { return ERR_FAILED; /* failure */ } #if MAG1_CPU_IS_LITTLE_ENDIAN *value = (int16_t)((val.buf[0]<<8)|val.buf[1]); /* transform into LE value */ #else *value = val.be; /* already in BE */ #endif return ERR_OK; }
/* ** =================================================================== ** Method : MAG1_Read16bitBEValue (component MAG3110) ** ** Description : ** Reads a 16bit value to the device. Value is read in Big Endian ** and returned in the proper format depending of LE/BE of ** microcontroller. ** This method is internal. It is used by Processor Expert only. ** =================================================================== */ byte MAG1_Read16bitBEValue(byte addr, word *value) { union { uint8_t buf[2]; /* value from device is in big endian */ uint16_t be; } val; uint8_t res; res = GI2C1_ReadAddress(MAG1_I2C_ADDR, &addr, sizeof(addr), &val.buf[0], sizeof(val.buf)); if(res!=ERR_OK) { return res; /* failure */ } #if MAG1_CPU_IS_LITTLE_ENDIAN *value = (uint16_t)((val.buf[0]<<8)|val.buf[1]); /* transform into LE value */ #else *value = val.be; /* already in BE */ #endif return ERR_OK; }
/* ** =================================================================== ** Method : GI2C1_ReadByteAddress8 (component GenericI2C) ** Description : ** Read a byte from the device using an 8bit memory address. ** This writes (S+i2cAddr+0), (memAddr), (Sr+i2cAddr+1), (data).. ** .(data+P) ** Parameters : ** NAME - DESCRIPTION ** i2cAddr - I2C Address of device ** memAddr - Device memory address ** * data - Pointer to read buffer (single byte) ** Returns : ** --- - Error code ** =================================================================== */ byte GI2C1_ReadByteAddress8(byte i2cAddr, byte memAddr, byte *data) { return GI2C1_ReadAddress(i2cAddr, &memAddr, sizeof(memAddr), data, 1); }
/* ************************************************************************** */ static void I2CreadBytes(stLSM9DS0_t * stThis, uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count) { byte registerAddress = (byte)(subAddress | 0x80); GI2C1_ReadAddress( address, ®isterAddress, 1, dest, count ); }