Pergunta

I am planning to implement a GPIO based I2C in atmega16. Since it should have two pins SCL, SDA. The SDA pin should be bi directional but what i know is that either we can set a pin as input or output at a time.

By what way we can implement it?

Foi útil?

Solução

The SDA pin should be bi directional but what i know is that either we can set a pin as input or output at a time.

This is true, but the I2C master "knows" when to expect incoming data. Since this is a synchronous bus, the master can switch between driving the output or switching to tri-state/input right before clocking data in/out.

This application note from Atmel may be useful to you: Atmel AVR156: TWI Master Bit Bang Driver

The example from Atmel uses a polling-approach, which limits speed. If one of your GPIOs has pin change interrupt support, you could probably utilize that to get more speed if required.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top