Skip to main content
Visitor II
December 14, 2022
Question

ASM330LHH didn't work in I2C with BLUENRG-LP

  • December 14, 2022
  • 2 replies
  • 1256 views

Here I used BLUENRG-LP SoC with ​ASM330LHH. We have the same schematic design in steval-IBD11V2A, like the first image. The second one is our schematic design.

0693W00000WL0FuQAL.png0693W00000WL0GTQA1.pngMy I2C configuration init function is like:

/**
 * @brief Configures the I2C interface used for the sensor ASM330LHH.
 * @param None
 * @retval None
 */
void BSP_I2C_Init(void)
{
 /* Initialize the GPIOs associated to the I2C port */
 BSP_I2C_DATA_GPIO_CLK_ENABLE();
 LL_GPIO_SetPinMode(BSP_I2C_DATA_GPIO_PORT, BSP_I2C_DATA_PIN, LL_GPIO_MODE_ALTERNATE);
 LL_GPIO_SetPinSpeed(BSP_I2C_DATA_GPIO_PORT, BSP_I2C_DATA_PIN, LL_GPIO_SPEED_FREQ_HIGH);
 LL_GPIO_SetPinOutputType(BSP_I2C_DATA_GPIO_PORT, BSP_I2C_DATA_PIN, LL_GPIO_OUTPUT_OPENDRAIN);
 LL_GPIO_SetPinPull(BSP_I2C_DATA_GPIO_PORT, BSP_I2C_DATA_PIN, BSP_I2C_DATA_GPIO_PULL);
 BSP_I2C_DATA_GPIO_AF();
 
 BSP_I2C_CLK_GPIO_CLK_ENABLE();
 LL_GPIO_SetPinMode(BSP_I2C_CLK_GPIO_PORT, BSP_I2C_CLK_PIN, LL_GPIO_MODE_ALTERNATE);
 LL_GPIO_SetPinSpeed(BSP_I2C_CLK_GPIO_PORT, BSP_I2C_CLK_PIN, LL_GPIO_SPEED_FREQ_HIGH);
 LL_GPIO_SetPinOutputType(BSP_I2C_CLK_GPIO_PORT, BSP_I2C_CLK_PIN, LL_GPIO_OUTPUT_OPENDRAIN);
 LL_GPIO_SetPinPull(BSP_I2C_CLK_GPIO_PORT, BSP_I2C_CLK_PIN, BSP_I2C_CLK_GPIO_PULL);
 BSP_I2C_CLK_GPIO_AF();
 
 /* Initialize the I2C clock */
 BSP_I2C_CLK_ENABLE();
 
 LL_I2C_Disable(BSP_I2C);
 
 /* Configure the SDA setup, hold time and the SCL high, low period
 * For Fast-mode 400 kHz, PRESC | 0h | SCLDEL | SDADEL | SCLH | SCLL
 * 1h | 0h | 3h | 2h | 03h | 09h
 */
 __IO uint32_t timing = __LL_I2C_CONVERT_TIMINGS(0x03, 0x04, 0x02, 0xF, 0x13);
 printf("timing in BSP_I2C_Init: %#x, \r\n", timing);
 LL_I2C_SetTiming(BSP_I2C, timing);
// LL_I2C_SetTiming(BSP_I2C, 0x10320309);
// LL_I2C_SetTiming(BSP_I2C, 0x00200204);
 
 
 /* Enable Clock stretching */
 LL_I2C_EnableClockStretching(BSP_I2C);
 
 /* Enable Peripheral in I2C mode */
 LL_I2C_SetMode(BSP_I2C, LL_I2C_MODE_I2C);
 
 /* Enable the I2C peripheral */
 LL_I2C_Enable(BSP_I2C);
 
 /* Enable I2C transfer complete/error interrupts:
 * - Enable Receive Interrupt
 * - Enable Not acknowledge received interrupt
 * - Enable Error interrupts
 * - Enable Stop interrupt
 */
// LL_I2C_EnableIT_TX(BSP_I2C);
// LL_I2C_EnableIT_RX(BSP_I2C);
// LL_I2C_EnableIT_TC(BSP_I2C);
// LL_I2C_EnableIT_NACK(BSP_I2C);
// LL_I2C_EnableIT_ERR(BSP_I2C);
// LL_I2C_EnableIT_STOP(BSP_I2C);
}

When I tried to use API, I can't get whoamI ID. The result is 0.

#ifdef TEST_INERTIAL_SENSOR
 
 
 
 /* Initialize the handle of the LPS22HH driver */
 
 inertialHandle.write_reg = BSP_I2C_Write;
 
 inertialHandle.read_reg = BSP_I2C_Read;
 
 
 
 /* Inizialize the I2C */
 
 BSP_I2C_Init();
 
 LL_mDelay(1000);
 
 
 
 /* Wait sensor boot time */
 
 LL_mDelay(BOOT_TIME);
 
 /* Check device ID */
 
 uint8_t result;
 
 asm330lhh_status_reg_t reg;
 
 result = asm330lhh_device_id_get(&inertialHandle, &whoamI);
 
 result = asm330lhh_status_reg_get(&inertialHandle,&reg);
 
 printf("whoamI: %d, \r\n", whoamI);
 
 printf("ID: %d, \r\n", ASM330LHH_ID);
 
 printf("result: %d, \r\n", result);

I don't know what's the problem. My guess is the set timing is wrong. Because I tried many times with different value.

    This topic has been closed for replies.

    2 replies

    Explorer
    January 22, 2023

    I have a similar problem. I am using HAL libraries instead of LL. Whit SPI I was able to read WHO_AM_I and temperature but was unable to get accelerometer and gyro data.

    EPeng.1Author
    Visitor II
    January 29, 2023

    Finally, I figured out where the problem is. I changed the codes: (in both BSP_I2C_Write and BSP_I2C_Read)

    From:

    LL_I2C_TransmitData8(BSP_I2C, (Reg | 0x80));

    To:

    LL_I2C_TransmitData8(BSP_I2C, Reg);

    Here raised a new question: Why we sometimes need Reg | 0x80, sometimes not?