I2C1 and I2C2 on RAK3172

Hi!

By default, RUI for Arduino use I2C2 on (PA11 and PA12). When using Wire or Wire1, both working on I2C2. I’d like to use I2C1 (PB6 and PB7), bit Wire library in RUI not accept define which pin use in object. PB6 and PB7 is used as Serial1 on RUI. Is it possible using I2C1?

I tried using a CubeIDE code

void MX_I2C1_Init(void)
{
    hi2c1.Instance = I2C1;
    // 0x00D00E28 100 kHz (Standard Mode)
    // 0x00300F33 400 kHz para PCLK1 = 16 MHz
    hi2c1.Init.Timing = 0x00D00E28;
    hi2c1.Init.OwnAddress1 = 0;
    hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
    hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
    hi2c1.Init.OwnAddress2 = 0;
    hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
    hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

    if (HAL_I2C_Init(&hi2c1) != HAL_OK)
    {
        //Error_Handler();
        Serial.println("Error init I2C");
    }
}

void MX_GPIO_Init(void)
{
    __HAL_RCC_GPIOB_CLK_ENABLE();
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

And I try send and read data using code bellow but don’t work.

if (HAL_I2C_Master_Transmit(&hi2c1, (I2C_SLAVE_ADDR << 1), txData, 3, 1000) == HAL_OK)
    {
        Serial.println("OK");
        HAL_Delay(100);
    } else { Serial.println("NOK"); }

Thank you

Mario

Thank you!

The RAK3172 has I2C1 on PA9 (SCL) and PA10 (SDA), not on PB6/PB7.

But I am not sure if you can use them through RUI3.

Hi, @beegee!

No, RAK3172 I2C2 is on PA11 and PA12, as I said.

Following the STM32WLE5CCU6 datasheet on page 53, pins PB6 and PB7 are I2C1 and pins PA11 and PA12 are I2C2 (RAK3172 default).

I2C1 don’t work using RUI. Wire and Wire1 always use I2C2. The Wire.h RUI version don’t have option to chose which pin to use for communication, as default Arduino Wire.h have.

If I use the STM32WL Arduino project, without RUI, I can use I2C1 and I2C2 correctly.

Thank you

Mario

Hi,

Are there any way to use I2C1? Using Wire.h from RUI don’t work. Using Softwareserial don’t work too. Look like RUI don’t allow softwareserial generate correct clock. It only worked withou RUI and Wire from RUI don’t allow select pin.

Thank you!