Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] I2C in STM32F103 longer data

Status
Not open for further replies.

aminpix

Advanced Member level 4
Joined
Sep 30, 2008
Messages
107
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
2,328
I am trying to use PCA9539 as an IOexpander for my project. I have a STM32F103 connected to PCA9539 via I2C.
The problem I have is to write into PCA9539. Based on the datasheet I should to send (1) address (2) command byte (3 and 4) data bytes via I2C. When I check the I2C bus lines with oscilloscope, I see the micro only sends 2 bytes after address byte. i.e. the last byte wont be send.

I use atollic and stm32cubeMX
Here is my code:
Code:
  HAL_GPIO_WritePin(GPIOF,I2C2_RST_Pin,'1');
  unsigned char I2C_2_buffer[8];
  I2C_2_buffer[0]=0x00; //command byte
  I2C_2_buffer[1]=0x50;
  I2C_2_buffer[2]=0x55;
  I2C_2_buffer[3]=0x00;

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {

	    /* USER CODE END WHILE */
		  HAL_Delay(4000);
		  HAL_GPIO_TogglePin(GPIOD,LED0_Pin);
  	          HAL_I2C_Master_Transmit(&hi2c2,0x76<<1,I2C_2_buffer,4,1000);
   	          HAL_Delay(1000);

		  
  }

.......
.......
.......
.......
.......
.......

static void MX_I2C2_Init(void)
{

  /* USER CODE BEGIN I2C2_Init 0 */

  /* USER CODE END I2C2_Init 0 */

  /* USER CODE BEGIN I2C2_Init 1 */

  /* USER CODE END I2C2_Init 1 */
  hi2c2.Instance = I2C2;
  hi2c2.Init.ClockSpeed = 100000;
  hi2c2.Init.DutyCycle = I2C_DUTYCYCLE_2;
  hi2c2.Init.OwnAddress1 = 0;
  hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c2.Init.OwnAddress2 = 0;
  hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C2_Init 2 */

  /* USER CODE END I2C2_Init 2 */

}
 

Did you check the oscilloscope if the slave is sending the acknowledge on the bus?
 

Yes, The slave sends the ACK.
 

I figure out what was the problem.
The expected code in the PCA9539 was different that what i have sent.
after sending the proper values it starts to work. Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top