Closed kholia closed 2 years ago
Possibly related https://community.st.com thread: Not able to read data from STM32G031 MCU I2C slave.
Possibly related issue:
If I enable clock stretching on this STM32G0 MCU, the SCL line goes down, and remains low forever. This could be a bug in my code but very similar code runs perfectly fine on a "Blue Pill" STM32 board with clock stretching enabled.
I fixed the HAL_I2C_AddrCallback
code in my project - by copy-pasting this function from a working example for another board.
I2C works great on a bare STM32G030J6 MCU chip now. I am using the STM32G030J6 MCU as an I2C Peripheral device.
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode) {
if (AddrMatchCode == 80) {
switch (TransferDirection) {
case I2C_DIRECTION_TRANSMIT:
if (HAL_I2C_Slave_Seq_Receive_IT(&hi2c2, rx_buff, 0x64u, I2C_FIRST_FRAME) != HAL_OK) {
// Error_Handler();
}
break;
case I2C_DIRECTION_RECEIVE:
HAL_I2C_Slave_Seq_Transmit_IT(&hi2c2, &TX_COMMAND[0], 16, I2C_FIRST_AND_LAST_FRAME);
++rx_counter;
break;
}
}
}
It would still be nice to have official I2C examples for STM32G0316-DISCO board.
Side-note: The HAL I2C stuff seems to suffer from a (harmless) bug where HAL_I2C_ErrorCallback is called with HAL_I2C_ERROR_AF for no discernible reason.
http://bfin.sakura.ne.jp/?p=1302 ran into the same problem it seems.
Hello @kholia, Please note that similaire HAL I2C examples are already available for STM32G031K8 MCU but on Nucleo board not the DISCO.
For more details please refer to the I2C_TwoBoards_RestartComIT example.
With Regards KORKAD
Thanks! This ticket may be closed.
Problem: The STM32G031J6 MCU (on a STM32G0316-DISCO board) is unable to work properly as an I2C Slave when operating in the Interrupt Mode with callbacks functions.
Details:
These screenshots show that the Slave is unable to handle
Data read
requests from the Master I2C device.The Slave returned data is always
0xFF
. I saw https://www.i2c-bus.org/i2c-primer/analysing-obscure-problems/data-bytes-from-slave-are-0xff/ on this topic.The I2 Master device is Arduino Pro Mini ATMega328P running @ 8 MHz @ 3.3v.
Note: I am using 2.2k pull-up resistors on the SDA and SCL lines. Removing them doesn't make any difference.
Here is the configured pinout for my STM32G031J6 MCU:
I2C2 global interrupt is enabled in my STM32CubeIDE project.
Here is how the I2C pins are configured:
Clocks are configured as below:
Note: In comparison, when I run a similar STM32CubeIDE project on my STM32F103C8T6 "Blue Pill" board, things just work well as expected (Slave is able to send back actual data).
I am attaching the source code for the I2C Master and I2C Slave (STM32G031J6) below:
Questions:
Is I2C Slave Mode (in
Interrupt Mode
) supported on STM32G031J6 MCU?Is there a reason why the STM32G0316-DISCO board software package has no
I2C
examples? They will be super helpful for users.What further information may I provide for debugging this problem? Thanks for your help! :)