/** * @file MMA.h * @brief Config MMA + LIB * @author Etienne LE JOLU * @version 1.0 */ #ifndef MMA_H_ #define MMA_H_ #define STATUS 0x00 #define F_STATUS 0x00 #define OUT_X_MSB 0x01 #define OUT_X_LSB 0x02 #define OUT_Y_MSB 0x03 #define OUT_Y_LSB 0x04 #define OUT_Z_MSB 0x05 #define OUT_Z_LSB 0x06 #define F_SETUP 0x09 #define TRIG_CFG 0x0A #define SYSMOD 0x0B #define INT_SOURCE 0x0C #define WHO_AM_I 0x0D #define XYZ_DATA_CFG 0x0E #define HP_FILTER_CUTOFF 0x0F #define PL_STATUS 0x10 #define PL_CFG 0x11 #define PL_COUNT 0x12 #define PL_BF_ZCOMP 0x13 #define P_L_THS_REG 0x14 #define FF_MT_CFG 0x15 #define FF_MT_SRC 0x16 #define FF_MT_THS 0x17 #define FF_MT_COUNT 0x18 #define TRANSIENT_CFG 0x1D #define TRANSIENT_SRC 0x1E #define TRANSIENT_THS 0x1F #define TRANSIENT_COUNT 0x20 #define PULSE_CFG 0x21 #define PULSE_SRC 0x22 #define PULSE_THSX 0x23 #define PULSE_THSY 0x24 #define PULSE_THSZ 0x25 #define PULSE_TMLT 0x26 #define PULSE_LTCY 0x27 #define PULSE_WIND 0x28 #define ASLP_COUNT 0x29 #define CTRL_REG1 0x2A #define CTRL_REG2 0x2B #define CTRL_REG3 0x2C #define CTRL_REG4 0x2D #define CTRL_REG5 0x2E #define OFF_X 0x2F #define OFF_Y 0x30 #define OFF_Z 0x31 /***************************Fonction MMA*************************************/ void writedataMMA(uint8_t reg, uint8_t data){ uint8_t values[2] = {0,0}; // Prepare for a write of 2 bytes I2C_TransferSeq_TypeDef i2cTransfert; values[0] = reg; values[1] = data; i2cTransfert.addr = 0x38; i2cTransfert.flags = I2C_FLAG_WRITE_WRITE; i2cTransfert.buf[0].len = 1; i2cTransfert.buf[0].data = &values[0]; i2cTransfert.buf[1].len = 1; i2cTransfert.buf[1].data = &values[1]; // Start I2C read int _status = I2C_TransferInit(I2C0, &i2cTransfert); while ( _status == i2cTransferInProgress) { _status = I2C_Transfer(I2C0); } //tfp_printf("Status : %d\r\n", _status); } uint8_t readdataMMA(uint8_t reg){ uint8_t values[2] = {0,0}; // Prepare for a write of 2 bytes I2C_TransferSeq_TypeDef i2cTransfert; values[0] = reg; values[1] = 0; i2cTransfert.addr = 0x39; i2cTransfert.flags = I2C_FLAG_WRITE_READ; i2cTransfert.buf[0].len = 1; i2cTransfert.buf[0].data = &values[0]; i2cTransfert.buf[1].len = 1; i2cTransfert.buf[1].data = &values[1]; // Start I2C read int _status = I2C_TransferInit(I2C0, &i2cTransfert); while ( _status == i2cTransferInProgress) { _status = I2C_Transfer(I2C0); } return values[1]; } /***************************************************************************//** * @brief * Séquence d'initialisation et de configuration de l'accéléromètre ******************************************************************************/ void initMMA(void){ writedataMMA(CTRL_REG2, 0x40); writedataMMA(CTRL_REG1, readdataMMA(CTRL_REG1)& ~(0x01)); // Standby // Fréquence d'echantillonage, Fréquence de coupure du filtre writedataMMA(XYZ_DATA_CFG, 0x00); writedataMMA(CTRL_REG1, 0x08); // Régalge des seuil pour la chute libre writedataMMA(FF_MT_CFG, 0xB8); writedataMMA(FF_MT_THS, 0x03); writedataMMA(FF_MT_COUNT, 0xC8); // Valeur à régler pour le temps de chute // Réglage des seuils pour la détéection du double tap writedataMMA(PULSE_CFG, 0x20); writedataMMA(PULSE_THSZ, 0x28); writedataMMA(PULSE_TMLT, 0x30); writedataMMA(PULSE_LTCY, 0x20); writedataMMA(PULSE_WIND, 0xFA); // Branchement des interruptions writedataMMA(CTRL_REG4, 0x0C); writedataMMA(CTRL_REG3, 0x02); writedataMMA(CTRL_REG5, 0x08); writedataMMA(CTRL_REG1, readdataMMA(CTRL_REG1)|0x01); } #endif