cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 ms5611 I2C HAL problem

starcu93
Associate
Posted on June 04, 2016 at 12:40

Hi i have problem with communication with ms5611 pressure sensor by I2C HAL library. Algorithms used to read registers look like in documentation:

http://www.meas-spec.com/downloads/MS5611-01BApdf

I done similar communication with StdPeriph library. I restarted device and obtained proper values of PROM memory by using code from example project and it's look like this: Reset:

void msInit()
{
printf(''DEV_TEST : '');
while(HAL_I2C_IsDeviceReady(&hi2c1, 119, 10, 100) != HAL_OK)
{
printf(''(DEV_READY)\n'');
break;
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
printf(''RESET : '');
while(HAL_I2C_Master_Transmit_IT(&hi2c1, 238, (uint8_t *)0x1E, 1) != HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
printf(''ERROR\n'');
}
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
printf(''(RESET_OK)\n'');
}

PROM:

void promRead()
{
while(HAL_I2C_Master_Transmit_IT(&hi2c1, 238, 0xA2, 1) != HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
printf(''ERROR\n'');
}
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
for(i = 0; i<6;i++)
{
while(HAL_I2C_Mem_Read_IT(&hi2c1, 238, promSense[i], 1, (uint8_t *)dataBuffer16, 2) != HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
printf(''ERROR\n'');
}
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
}
}

and callback:

void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
{
promData = (dataBuffer16[0]<<8)|dataBuffer16[1];
printf(''%u \n'', promData);
}

I'm trying to obtain pressure values with code like this:

void pressureRead()
{
while(HAL_I2C_Master_Transmit_IT(&hi2c1, 238, 0x42, 1) != HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
printf(''ERROR\n'');
}
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
while(HAL_I2C_Master_Transmit_IT(&hi2c1, 238, 0x00, 1) != HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
printf(''ERROR\n'');
}
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
while(HAL_I2C_Mem_Read_IT(&hi2c1, 238, 0x00, 1, (uint8_t *)dataBuffer24, 3) != HAL_OK)
{
/* Error_Handler() function is called when Timout error occurs.
When Acknowledge failure ocucurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)
{
Error_Handler();
printf(''ERROR\n'');
}
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY){}
}

And it still return 0 values in similar callback as with PROM data read. I don't know what to do next because im new in STM32 and CubeMX, should i restart some flag? Please for help. #stm32 #i2c #ms5611
0 REPLIES 0