0
\$\begingroup\$

I am using an STM32 NUCLEO-F042K6 dev board to interact with a MCP4451 digital pot. I want to be able to adjust the wiper values through i2c. I am using the STM32CubeIDE and the HAL library to interface.

 static const uint8_t POT_ADDRESS = 0x58;
 static const uint8_t INCREMENT = 0x94;

  while (1) {
  buf[0] = INCREMENT;
  ret = HAL_I2C_Master_Transmit(&hi2c1, POT_ADDRESS, buf, 2, HAL_MAX_DELAY);
  if (ret != HAL_OK) {
      strcpy((char*)buf, "Error Tx\r\n");
  } else {
      strcpy((char*)buf, "YEET\r\n");
  }

  HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY);

  HAL_Delay(200);
  }

I have the correct configuration, but I keep getting "Error Tx" on the serial monitor. I made sure to power the i2c lines with pull-up resistors to 3.3V. I'm a bit lost as to what to do.

\$\endgroup\$
13
  • \$\begingroup\$ Debug by looking at the condition if (ret != HAL_OK) { strcpy((char*)buf, "Error Tx\r\n"); What does that tell you? \$\endgroup\$
    – user103380
    Commented Feb 4, 2020 at 20:51
  • \$\begingroup\$ What value pull-up resistors did you use? \$\endgroup\$
    – Ron Beyer
    Commented Feb 4, 2020 at 20:53
  • \$\begingroup\$ Potentially your address is wrong for following reason : 1. The address set bits are wrong ? \$\endgroup\$
    – ManojKumar
    Commented Feb 4, 2020 at 20:56
  • \$\begingroup\$ @RonBeyer I used 2.7k resistors \$\endgroup\$ Commented Feb 4, 2020 at 20:59
  • 1
    \$\begingroup\$ @koreamaniac101 If the result is not HAL_OK, then it is something else. It will be easiest to just open the I2C HAL code and see what possible return values there are, but most likely there will be HAL_BUSY, HAL_ERROR or HAL_TIMEOUT, and for the case of error, the I2C instance contains an ErrorCode you can get for further info. It is difficult to say anything specific as each STM32 has wildly different I2C peripherals and HAL libraries for it. It is also worth to check SDA and SCL are connected the right way around, so that they are not swapped. \$\endgroup\$
    – Justme
    Commented Feb 4, 2020 at 21:13

1 Answer 1

0
\$\begingroup\$

My supervisor found the issue. The digital pot runs off of 5V, but since the i2c line runs at 3.3V, it wasn't registering digital high properly. Since the STM32 pins on my dev board are 5V, as soon as I ran everything on 5V, I got an ok status.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.