0
\$\begingroup\$

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. The PCA9539 sends the ACK.

I use atollic and stm32cubeMX

Here is my 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 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 */
}
jsotola
2,9253 gold badges15 silver badges22 bronze badges
asked Jul 4, 2019 at 17:00
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You are trying to write to an input data register. That makes not sense and the chip may consider this as invalid write operation. Try writing to the registers that have defined write operations.

answered Jul 4, 2019 at 19:38
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.