0
\$\begingroup\$

I'm trying to use I2C between an STM32F103C8T6 development board and an Arduino Uno.

However, I always get a HAL_BUSY error when I call HAL_I2C_Master_Transmit in the code below.

(I used 10K pullup resistors at SCL and SDA) on the STM32 side and a logic level converter between STM32 and Arduino.

How can I send messages from the STM32 to the Arduino?

int main(void)
{
  ...
  MX_I2C1_Init();

  char buffer[16];
  strcpy((char*) buffer,  (const char*) "Test 1");

  while (1)
  {
      HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_14);
      HAL_Delay(1000);

      if (HAL_I2C_Master_Transmit(&hi2c1, 8, (uint8_t *) buffer,  7, 1000) != HAL_OK)
      {
          HAL_Delay(1000);
      }

Settings (all default):

  hi2c1.Instance = I2C1;
  hi2c1.Init.ClockSpeed = 100000;
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
  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;
\$\endgroup\$
  • 1
    \$\begingroup\$ Is the Arduino address '8'? \$\endgroup\$ – Long Pham Jul 6 at 14:40
  • 1
    \$\begingroup\$ Yeah I know :) BTW, HAL I2C functions require left shifted address. \$\endgroup\$ – Long Pham Jul 6 at 15:04
  • 1
    \$\begingroup\$ Maybe your problem is the same as this. \$\endgroup\$ – Long Pham Jul 6 at 15:47
  • 1
    \$\begingroup\$ Try it without level shifters, all possible I2C pins are 5V tolerant on the STM32F1. Are the GPIO pins set to open-drain? \$\endgroup\$ – berendi - protesting Jul 7 at 19:37
  • 1
    \$\begingroup\$ Did you initialise wire library in UNO with : wire.begin(0x8); \$\endgroup\$ – Meenie Leis Jul 8 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.