Skip to main content
NJali.1
Associate
February 27, 2022
Solved

Please help with porting this arduino library. I have to use HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive to write to an i2c and I have no clue how to do.

I have this functions to work with:

void write8(uint8_t reg, uint32_t value)

read8(uint8_t reg)

I am a newbie when it comes to c programming and have little knowledge when it comes to registers and how to write and read them.

Right now the functions look something like this:

void Adafruit_TCS34725::write8(uint8_t reg, uint32_t value) {
 uint8_t buffer[2] = {TCS34725_COMMAND_BIT | reg, value & 0xFF};
 i2c_dev->write(buffer, 2);
}
 
uint8_t Adafruit_TCS34725::read8(uint8_t reg) {
 uint8_t buffer[1] = {TCS34725_COMMAND_BIT | reg};
 i2c_dev->write_then_read(buffer, 1, buffer, 1);
 return buffer[0];
}

Please help :(

This topic has been closed for replies.
KnarfB
KnarfBBest answer
Super User
February 28, 2022

There is a .7z download on https://www.waveshare.com/wiki/TCS34725_Color_Sensor

hth

KnarfB

4 replies

KnarfB
Super User
February 28, 2022

Check out the HAL_I2C_Mem_Write and HAL_I2C_Mem_Read functions. There are also STM32 ports out in the web for your studies.

hth

KnarfB

NJali.1
NJali.1Author
Associate
February 28, 2022

Thank you for your reply!

I have tried looking for relevant stm32 ports but I could not find any. Would you mind reffering me one?

regarding the functions. I find it difficult to fill out all the parameters required for those two. As far as i know, the trasmit and recieve do the same without a memory adress. Since Adafruit_TCS34725::write8 only uses two parameters containing reg and value, how would I fill out the other ones?

Thanks!

KnarfB
KnarfBBest answer
Super User
February 28, 2022

There is a .7z download on https://www.waveshare.com/wiki/TCS34725_Color_Sensor

hth

KnarfB

NJali.1
NJali.1Author
Associate
February 28, 2022

Thank you so much. Great help!