cancel
Showing results for 
Search instead for 
Did you mean: 

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

Dunk
Visitor

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.

4 REPLIES 4
Dunk
Visitor

I meant 0x12 to 0x13.

TDK
Super User

All of these examples are working examples:

https://github.com/STMicroelectronics/STM32CubeG0/tree/master/Projects

 

Here is an I2C example:

STM32CubeG0/Projects/NUCLEO-G031K8/Examples/I2C/I2C_TwoBoards_ComPolling/Src/main.c at 24d13255ffa4eca73d133561a3df72f7df90d302 · STMicroelectronics/STM32CubeG0

 

Consider showing your code or following an existing working example.

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Super User

Are you sure you are correctly justifying the 7-bit address ?

https://community.st.com/t5/imaging-sensors/vl53l8cx-not-working-on-nrf9151-and-getting-naks/m-p/814452/highlight/true#M5697

 

Please give some more details of your setup:

How to write your question to maximize your chances to find a solution

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.

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();

}