1
\$\begingroup\$

I have problem with PCF8754 component. The PCF8754 is connected to stm32 MCU and PINS A2, A1, A0 are connected to GND. It means, that 7bit address is 0x20. I want read pin state(P0 to P7), and write state(P0, to P7). I use HAL library. Function for write:

HAL_I2C_Mem_Write(&hi2c1, 0x20, MemAddress, 1, &val, 1, 1);

Function for read:

HAL_I2C_Mem_Read(&hi2c1, 0x20, MemAddress, 1, &data, 6, 100);

I don't know MemAddress(register) for read and write data from/to pcf8574. Where to find it?

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to EE.SE. Could you please provide us with a PCF8754 diagram and a basic schematic or your circuit. \$\endgroup\$ – Sparky256 Jul 16 '16 at 21:31
  • 1
    \$\begingroup\$ Don't you have the datasheet? \$\endgroup\$ – Mark Jul 16 '16 at 21:37
  • \$\begingroup\$ I'm uncertain and haven't investigated the function calls listed, but does the address have to do with the I2C device or with the serial peripheral being used in the MCU? Which "HAL Library" are you using? \$\endgroup\$ – user2943160 Jul 16 '16 at 22:38
  • \$\begingroup\$ You should left shift the device address with one bit when passing it to the functions. \$\endgroup\$ – Bence Kaulics Jul 17 '16 at 8:18
3
\$\begingroup\$

To find information about registers (addresses, contents) read the datasheet. This applies to every IC.

PCF8754 has got only one register (see p.7), which isn't a typical architecture for an I2C I/O expander1. The details on how to read and write to it are in sections 8.2 and 8.3 in the datasheet.

1 For a more typical register arrangement, see PCA9555. The PCF8754 is an older part. The PCA9555 is a newer part.

Since there is only one register, the very first byte which the bus master sends over the I2C is data: the contents of the register. The register address isn't sent. Your software library function, however, semantically separates the register address byte from data bytes.

  1. Look for another library function that doesn't have a parameter for register address.
  2. Or, write your own such function.
  3. Or, use the byte address for sending data. (That would be a hack, though. Somebody else reading your code later might not appreciate it.)
\$\endgroup\$
  • 2
    \$\begingroup\$ The corresponding HAL functions are HAL_I2C_Master_Transmit() for writing data and HAL_I2C_Master_Receive() for reading. \$\endgroup\$ – Bence Kaulics Jul 17 '16 at 8:01
0
\$\begingroup\$

I have found following functions:

HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);

HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);

HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);

HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);

It seems, that I should use first and second function for communication between stm32 and pcf8754. Thank you.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.