Other Parts Discussed in Thread: CC3220SF
Hi,
When I try to read the CHIP ID of BMM150 I get the value 0xFF. The correct CHIP ID value is 0x32. Is there anything wrong with my I2C Code?
/* * ======== mainThread ======== */ void *mainThread(void *arg0) { unsigned int i; int8_t MagX, MagY, MagZ; I2C_Handle i2c; I2C_Params i2cParams; /* Call driver init functions */ Display_init(); GPIO_init(); I2C_init(); /* Configure the LED pin */ GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); /* Open the HOST display for output */ display = Display_open(Display_Type_UART, NULL); if (display == NULL) { while (1); } /* Turn on user LED */ GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON); Display_printf(display, 0, 0, "Starting the i2cbme280 example\n"); /* Create I2C for usage */ I2C_Params_init(&i2cParams); i2cParams.transferMode = I2C_MODE_BLOCKING; i2cParams.transferCallbackFxn = NULL; i2cParams.bitRate = I2C_400kHz; i2c = I2C_open(0, &i2cParams); if (i2c == NULL) { Display_printf(display, 0, 0, "Error Initializing I2C\n"); while (1); } else { Display_printf(display, 0, 0, "I2C Initialized!\n"); } // Init the BME280 API BMM150_init(i2c, 0x13); if (!BMM150_open()) { Display_printf(display, 0, 0, "ERROR opening BMM150_open()\n"); //always go here } else { Display_printf(display, 0, 0, "BMM150 opened; polling every\r\n"); } #if 0 /* Take 20 samples and print them out onto the console */ for (i = 0; i < 50; i++) { // Read & interpret results, spitting to CIO console BMM150_ReadNew(&MagX, &MagY, &MagZ); sprintf(ubuf, "MagX: %d MagX: %d MagY: %d", (int16_t)MagX, (int16_t)MagY, (int16_t)MagZ); Display_printf(display, 0, 0, "%s", ubuf); /* Sleep for 1 second */ sleep(1); } #endif /* Deinitialized I2C */ I2C_close(i2c); Display_printf(display, 0, 0, "I2C closed!\n"); return (0); }
bool BMM150_open(void) { uint8_t readId; uint8_t reg_data; /* Power up the sensor from suspend to sleep mode */ reg_data = BMM150_readReg(BMM150_POWER_CONTROL_ADDR); //0x4B reg_data = reg_data | BMM150_POWER_CNTRL_ENABLE; //0x01 BMM150_writeReg(BMM150_POWER_CONTROL_ADDR, reg_data); // Start-up time delay of 3ms Task_sleep(BMM150_RESET_SETTLING_TIME); // Find Chip ID readId = BMM150_readReg(BMM150_CHIP_ID_ADDR); //0x40 if (readId != BMM150_CHIP_ID) { // Not a BMM150? //0x32 return false; } return true; }
/// @brief Write a single 8-bit value to a specified memory address void BMM150_writeReg(uint8_t memAddress, uint8_t value) { I2C_Transaction txn; uint8_t wrBuf[2]; txn.readBuf = NULL; txn.readCount = 0; txn.writeBuf = wrBuf; txn.writeCount = 2; txn.slaveAddress = i2cAddr; wrBuf[0] = memAddress; wrBuf[1] = value; I2C_transfer(i2cbus, &txn); } /// @brief Read a single 8-bit value from the specified memory address uint8_t BMM150_readReg(uint8_t memAddress) { I2C_Transaction txn; uint8_t regAddr = memAddress; uint8_t rdBuf; txn.readBuf = &rdBuf; txn.readCount = 1; txn.writeBuf = ®Addr; txn.writeCount = 1; txn.slaveAddress = i2cAddr; I2C_transfer(i2cbus, &txn); return rdBuf; }
-kel