cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Interface HAL

bhavesh
Associate II
Posted on October 06, 2015 at 19:46

STM32F4xx HAL Driver Problem With I2C Write Data

I Want To Send Command In form of Int but in HAL Driver not Able to Send it and also Null Character for DS1621,

int main(void)

{

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_I2C1_Init();

  while (1)

  {

    HAL_I2C_IsDeviceReady(&hi2c1, 0x90, 10, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0xAC'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0x02'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0xA1'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0x28'', 2, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0x00'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0xA2'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0x0A'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0x00'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0xEE'', 1, 1000);

    HAL_I2C_Master_Transmit(&hi2c1, 0x90, ''0xAA'', 1, 1000);

    HAL_I2C_Master_Receive(&hi2c1, 0x91, Temp, 2, 1000);

    __HAL_I2C_DISABLE(&hi2c1);

    delay__(2);

    __HAL_I2C_ENABLE(&hi2c1);

  }

}

/** System Clock Configuration*/

void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct;

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

  RCC_OscInitStruct.HSIState = RCC_HSI_ON;

  RCC_OscInitStruct.HSICalibrationValue = 16;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

  RCC_OscInitStruct.PLL.PLLM = 10;

  RCC_OscInitStruct.PLL.PLLN = 210;

  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

  RCC_OscInitStruct.PLL.PLLQ = 4;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1

                              |RCC_CLOCKTYPE_PCLK2;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

}

/* I2C1 init function */

void MX_I2C1_Init(void)

{

  hi2c1.Instance = I2C1;

  hi2c1.Init.ClockSpeed = 400000;

  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;

  hi2c1.Init.OwnAddress1 = 180;

  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;

  hi2c1.Init.OwnAddress2 = 0;

  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;

  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;

  HAL_I2C_Init(&hi2c1);

}

void MX_GPIO_Init(void)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */

  __GPIOD_CLK_ENABLE();

  __GPIOB_CLK_ENABLE();

  /*Configure GPIO pins : PD12 PD13 PD14 PD15 */

  GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;

  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;

  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

}

&sharpifdef USE_FULL_ASSERT

void assert_failed(uint8_t* file, uint32_t line)

{

}

&sharpendif

Frequency is 168Mhz

please help me how to it work for DS1621 Digital Temp., Sensor

i get data always 0xFF80 while Standard peripheral Work well with F4 And F0

i Want to use it using HAL Driver because my other work is based on HAL driver

#i2c-stm32f4xx-hal-driver-problem
2 REPLIES 2
Posted on October 07, 2015 at 15:59

Hi moradiya.bhavesh,

''i get data always 0xFF80 while Standard peripheral Work well with F4 And F0''

 

the data, you are refering to, is the value that you read from the slave? or the data you read on the bus after transmission?

Try to transmit only one data and read the bus with an oscilloscope, and give us the result.

-Shahrzad- 
bhavesh
Associate II
Posted on January 12, 2016 at 13:11

thank you for help,

i solve out my problem there is i2c ack signal problem found on CRO, sensor work fine.

thank you