cancel
Showing results for 
Search instead for 
Did you mean: 

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

MGhob.1
Associate
 
2 REPLIES 2
Peter BENSCH
ST Employee

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
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.