how can i convert my simple few lines i2c wire library based arduino code to STM HAL api based code ?
Could someone please help me to convert My tested arduino code on STM32, now using HAL apis to drive same code :
#include <Wire.h>
int16_t X, Y, Z = 0;
const uint8_t STK8321 = 0x0F;
const uint8_t startRegister = 0x02;
void printAcceleration() {
byte acceleration[6];
Wire.beginTransmission(STK8321);
Wire.write(startRegister);
Wire.endTransmission();
Wire.requestFrom(STK8321, 6);
uint16_t XL = Wire.read();
uint16_t XH = Wire.read();
X = (XH << 8) | XL;
X = X >> 4;
uint16_t YL = Wire.read();
uint16_t YH = Wire.read();
Y = (YH << 8) | YL;
Y = Y >> 4;
uint16_t ZL = Wire.read();
uint16_t ZH = Wire.read();
Z = (ZH << 8) | ZL;
Z = Z >> 4;
Serial.print(" X "); Serial.print(X); Serial.print("/");
Serial.print(" Y "); Serial.print(Y); Serial.print("/");
Serial.print(" Z "); Serial.println(Z);
}
void setup() {
Serial.begin(115200);
Wire.begin();
}
void loop() {
delay(500);
printAcceleration();
}
