Skip to main content
Associate
October 17, 2023
Question

code from Arduino to STM32CubeIDE

  • October 17, 2023
  • 3 replies
  • 1393 views

Hello everyone,

 

I'm new in STM32CubeIDE, and I work on I2C issues. I've wrote the below code in Arduino, but I can't set the some codes for STM32CubeIDE.

How I can adjust the below codes for STM32CubeIDE?

Thanks in advance.

 

Codes:

#define REGMAP_ORG 0x00
#define SLAVE_ADDRESS 0x32
#define CTRL_CMD 0x86
#define SAVE_CHECK_CRC 0x02

 

Wire.beginTransmission(SLAVE_ADDRESS); // transmit to device #0x32
Wire.write(REGMAP_ORG); // sends offset byte
Wire.write(00);
Wire.endTransmission(); // stop transmitting

 

Wire.beginTransmission(SLAVE_ADDRESS); // transmit to device #0x32
Wire.write(CTRL_CMD);
Wire.write(SAVE_CHECK_CRC);
Wire.endTransmission(); // stop transmitting

 

Wire.requestFrom(SLAVE_ADDRESS, 2); //2 bytes

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    October 17, 2023

    Use HAL

    Use perhaps functions HAL_I2C_Mem_Read() and HAL_I2C_Mem_Write() for internal address / byte(s) type communication.Or look at related HAL I2C functions, and examples.

    https://github.com/cturvey/RandomNinjaChef/blob/main/STM32_uBlox_I2C.c

    https://github.com/cturvey/RandomNinjaChef/blob/main/MKRWAN1300_SAM_M8Q_I2C.ino

     

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Rim LANDOLSI
    ST Employee
    October 17, 2023

    Hello @hdhdhd  and welcome to the community,

     

    This wiki could help you develop a project based on I2C communication.

     

    Thanks,

    Rim.

    hdhdhdAuthor
    Associate
    October 20, 2023

    Thanks for replying @Rim LANDOLSI @Tesla DeLorean