aminpix
Full Member level 2
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:
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 */
}