Question
hello i'm trying to make a project whit stm32f401ve and Digital Thermometer DS1621 using I2C protocol, and I have a problem whit i2c receive. here is my source code and photos of datasheet and simulation any help will be appreciated
static const uint16_t TEMP_ADRESS = 0x48<<1;
int main(void)
{
HAL_StatusTypeDef RETURN ;
uint8_t buffer[1];
uint8_t buffer2[2];
uint16_t Val ;
float temp_c ;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_I2C1_Init();
buffer[0]=0xEE;
RETURN= HAL_I2C_Master_Transmit(&hi2c1, TEMP_ADRESS, buffer, 1, HAL_MAX_DELAY);
if(RETURN!=HAL_OK)
{
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, "step 1 ERUUR");
HAL_Delay (2000);
}
else
{
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, "step 1 DON ");
HAL_Delay (2000);
Lcd_clear(&lcd);
}
while (1)
{
buffer[0]=0xAA;
RETURN = HAL_I2C_Master_Transmit(&hi2c1, TEMP_ADRESS, buffer, 1, HAL_MAX_DELAY);
if(RETURN != HAL_OK)
{
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, "* step 2 ERRUR*");
HAL_Delay (2000);
Lcd_clear(&lcd);
}
else
{
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, "step 2 DON");
HAL_Delay (2000);
Lcd_clear(&lcd);
RETURN = HAL_I2C_Master_Receive(&hi2c1, TEMP_ADRESS,buffer2, 2, 10000);
if(RETURN != HAL_OK)
{
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, "*step 3 ERRUR*");
HAL_Delay (2000);
Lcd_clear(&lcd);
}
else
{
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, " step 3 DON");
HAL_Delay (2000);
Lcd_clear(&lcd);
Val = ((int16_t)buffer2[0]<<4) | (buffer2[1]>>4);
if(Val>0x7FF)
{
Val|=0xF000;
}
temp_c= Val*0.0625;
temp_c*=100;
sprintf((char*)buffer2,"Temp = %u.%u",((unsigned int)temp_c/100),((unsigned int)temp_c% 100));
Lcd_cursor(&lcd, 0,0);
Lcd_string(&lcd, buffer2);
HAL_Delay (2000);
Lcd_clear(&lcd);
}
}


