cancel
Showing results for 
Search instead for 
Did you mean: 

code from Arduino to STM32CubeIDE

hdhdhd
Associate II

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

3 REPLIES 3

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
Up vote any posts that you find helpful, it shows what's working..
Rim LANDOLSI
ST Employee

Hello @hdhdhd  and welcome to the community,

 

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

 

Thanks,

Rim.

hdhdhd
Associate II

Thanks for replying @Rim LANDOLSI @Tesla DeLorean