2026-01-13 8:55 AM
Hello,
I have tried a number of I2C slave tutorials found on YouTube with no success, but none are specifically for the STM32G03 series. Also I am getting a very strange phenomenon. In CubeMX for I2C2 I set the first slave address to 0x012. On my PC I am using python with a USB adapter to scan() the bus. I have an EEprom on the same bus an the scan address is correct but for the MCU it returns 0x13?
Has anyone encountered this address shift?
Is there ANY WORKING examples for this MCU series?
This is my first post on this community.
2026-01-13 8:58 AM
I meant 0x12 to 0x13.
2026-01-13 9:07 AM
All of these examples are working examples:
https://github.com/STMicroelectronics/STM32CubeG0/tree/master/Projects
Here is an I2C example:
Consider showing your code or following an existing working example.
2026-01-13 9:08 AM
Are you sure you are correctly justifying the 7-bit address ?
Please give some more details of your setup:
How to write your question to maximize your chances to find a solution
2026-01-13 10:23 AM - last edited on 2026-01-14 2:14 AM by Andrew Neil
Code generated by CubeMX -
/* USER CODE END I2C2_Init 1 */
hi2c2.Instance = I2C2;
hi2c2.Init.Timing = 0x10707EBE;
hi2c2.Init.OwnAddress1 = 36;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.OwnAddress2 = 0;
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c2) != HAL_OK)
{
Error_Handler();
}Edited to apply source code formatting - please see How to insert source code for future reference.
2026-01-14 9:12 AM
Before I list any of my code I have something regarding the CubeMX configuration that is puzzling me -
According to the reference https://www.st.com/resource/en/reference_manual/rm0444-stm32g0x1-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
Section 32.6 - Is this listing TWO interrupts required - I2C_EV & I2C_ERR ?
CubeMX V 6.16.1 for this MCU seems to only have an enable for a single "I2C2 Global interrupt"
The example videos online demonstrating an I2C slave with an STM32F103 show two interrupts available in the CubeMX - Event interrupt & Error interrupt.
Please Clarify?