Skip to main content
MGhob.1
Visitor II
January 20, 2022
Question

What is the similar code in stm8? HAL_I2C_Mem_Write for ssd1306 i2c

  • January 20, 2022
  • 2 replies
  • 2058 views

..

This topic has been closed for replies.

2 replies

Peter BENSCH
ST Technical Moderator
January 20, 2022

Welcome, @MGhob.1​, to the community!

HAL is a layer of abstraction which is not available for the STM8. So sending a memory block via I2C has to be done manually there, for which you can use the SPL: I2C_Send7bitAddress(), I2C_SendData() etc.

Good luck!

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
WilkoL
Senior
February 10, 2022
void I2C_sendarray_reg8(uint8_t dev_address, uint8_t reg8_register, uint8_t *data_array, uint8_t datalength)
{
	uint8_t i;
	
	i = 0;
	
	I2C_GenerateSTART(ENABLE);													//startbit
	while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));						//master-mode?
	
	I2C_Send7bitAddress(dev_address, I2C_DIRECTION_TX);							//write-address-of reg16
	while(!I2C_CheckEvent( I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));		//transmit-mode?
	
	I2C_SendData((uint8_t) reg8_register);										//reg8 register
	while(I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET);				//byte is sent?
	
	while (i < datalength)
	{
		I2C_SendData(data_array[i++]);											//send reg16 data byte
		while(!I2C_CheckEvent( I2C_EVENT_MASTER_BYTE_TRANSMITTED));				//byte is sent?
	}
	I2C_GenerateSTOP(ENABLE);													//stopbit
}

you'll have to write it yourself, above is some code as an example.