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!