Skip to main content
Associate II
January 13, 2026
Question

Any tutorial or example code for STM32G0 I2C slave? And a very strange addressing problem.

  • January 13, 2026
  • 3 replies
  • 467 views

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.

3 replies

DunkAuthor
Associate II
January 13, 2026

I meant 0x12 to 0x13.

TDK
Super User
January 13, 2026
"If you feel a post has answered your question, please click ""Accept as Solution""."
DunkAuthor
Associate II
January 14, 2026

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?

Andrew Neil
Super User
January 13, 2026
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
DunkAuthor
Associate II
January 13, 2026

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.