Skip to main content
Associate III
October 22, 2024
Solved

HAL_BUSY from LM75 via I2C on STM32L0538-Discovery

  • October 22, 2024
  • 5 replies
  • 1678 views

Hello,

I tried to get temperature data from LM75 via I2C on STM32L0538-Discovery.

But in following test program, HAL_I2C_Master_Transmit() and HAL_I2C_Master_Receive() returned HAL_BUSY.

What's wrong with it?

And I couldn't check from the schematic diagram on UM1775 if LM75 is connected with the STM32L0538.

Please show me how to solve it.

Thanks

This topic has been closed for replies.
Best answer by Andrew Neil

@curiae  has that resolved your issue?

If so, please mark the solution:

https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256 

5 replies

curiaeAuthor
Associate III
October 22, 2024

Hello,

Now I found source codes in my post was deleted so I'll post again.

I tried to get temperature data from LM75 via I2C on STM32L0538-Discovery.

In following test program, HAL_I2C_Master_Transmit() and HAL_I2C_Master_Receive() returned HAL_BUSY.

Though in MX_I2C1_Init()  hi2c->State was HAL_OK, but entering to HAL_I2C_Master_Transmit(), hi2c->State was changed to HAL_BUSY.

I thought LM75 is not connected with MCU,  I couldn't check from the schematic diagram on UM1775 if LM75 is connected with the STM32L0538 or not.

Please show me how to solve it.

Thanks

 

 

#define LM75_ADDR					(0x90 << 1)
#define LM75_REG_TEMP				0x00 // Temperature

int main(void)
{
	HAL_Init();
	SystemClock_Config();
	MX_GPIO_Init();
	MX_RTC_Init();
	MX_I2C1_Init();
	// I2C test
 uint8_t data_write[2];
 uint8_t data_read[2];
 HAL_StatusTypeDef ret, ret_rec;
 I2C_HandleTypeDef *handle;
 data_write[0] = LM75_REG_TEMP;
 ret = HAL_I2C_Master_Transmit(handle, LM75_ADDR, data_write, 1, MAX_DELAY);
 HAL_Delay(100);
 ret_rec = HAL_I2C_Master_Receive(handle, 0xb9, data_read, 2, MAX_DELAY);
	while(1)
	{
	}	
}

void MX_I2C1_Init(void)
{
	hi2c1.Instance = I2C1;
	hi2c1.Init.Timing = 0x10A13E56; // 100KHz
	hi2c1.Init.OwnAddress1 = 0;
	hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
	hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
	hi2c1.Init.OwnAddress2 = 0;
	hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
	hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
	hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
	if(HAL_I2C_Init(&hi2c1) != HAL_OK)
	{
		Error_Handler();
	}
	// Configure Analog filter
	if(HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
	{
		Error_Handler();
	}
	// Configure Digital filter
	if(HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
	{
		Error_Handler();
	}
}

 

 

 

Andrew Neil
Super User
October 22, 2024

@curiae wrote:

Now I found source codes in my post was deleted so I'll post again.


No need to start a separate thread - you could have just edited the original, or added a reply.

Merged with the original.

 


@curiae wrote:

I couldn't check from the schematic diagram on UM1775 if LM75 is connected with the STM32L0538 or not.


I don't see any mention of an LM75 in any of this board's documentation:

https://www.st.com/en/evaluation-tools/32l0538discovery.html

But it does appear on the schematic:

AndrewNeil_0-1729588998181.png

https://www.st.com/resource/en/schematic_pack/mb1143-l053c8t6-b03_schematic.pdf#page=5 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
curiaeAuthor
Associate III
October 22, 2024

Sorry, I should have written formal name STLM75.

Could you tell me why HAL_I2C_Master_Transmit() and HAL_I2C_Master_Receive() returned HAL_BUSY.

There are something wrong in MX_I2C1_Init()?