3

I want to get and change the I²C address of MCP4728 chip. To do this, one has to coordinate I²C communication with another LDAC pin register. After posting the question here, Reading and writing with smbus package, I have realised that the only way to do that is by I²C bit-banging.

The part with I²C communication protocol is easy, as there is plenty of documentation and examples on Internet. However, there is scarce (if any) documentation on Internet about the rest. I therefore decided to start a new question.

  1. How can one bit-bang using Python?

  2. How can one use arbitrary GPIO in open drain mode using Python?

Theoretically, both is achieved by fixing GPIO state to a fixed False and toggle the output enable switch/output register.

Please provide a link to documentation/example or add your own example. It is desirable that as few as possible GPIO libraries are used. Embedding C (if this is the only reasonable solution) is also a possibility.

Thanks a lot!

EDIT:

The problem is finally solved. You can find the library with read/update I2C address for MCP4728 on http://www.pinteric.com/raspberry.html#dac

Pygmalion
  • 458
  • 2
  • 7
  • 25

1 Answers1

3

1) Bit banging just means using software rather than hardware to implement a communications protocol. To bit bang I2C this means to control the SDA and SCL signals in software. SDA is connected to GPIO 2 (pin 3), SCL is connected to GPIO 3 (pin 5). Generally to bit bang you need to set the GPIO high (write 1) or low (write 0). All the Pi GPIO libraries support such control of the GPIO.

2) The Pi GPIO do not have an open drain mode. Fortunately it is easy to simulate for the I2C protocol as the protocol requires pull-up resistors to Vcc to be present.

To simulate open drain

  • to signal low set the GPIO to be an OUTPUT and write 0 to the GPIO.
  • to signal high set the GPIO to be an INPUT (the GPIO will float high to the pull-up, unless overridden by another bus device).
joan
  • 71,852
  • 5
  • 76
  • 108