rambo / TinyWire

My modifications to TinyWire Arduino libs
284 stars 121 forks source link

SCL SDA pin change #10

Closed paulplpl closed 8 years ago

paulplpl commented 10 years ago

Hi Rambo,

I tied using your library with standard pins (PA4, PA6) on Attiny84. Works like charm! However, those pins are already in use by the SPI interface. I tried changing the I2C pins to PA3 and PA2 in usiTwiSlave.c as:

'#if defined(AVR_ATtiny84) ..... '# define PORT_USI_SDA PORTA3 // was PORTA6 SDA '# define PORT_USI_SCL PORTA2 //was PORTA4 SCL '# define PIN_USI_SDA PINA3 //was PINA6 SDA '# define PIN_USI_SCL PINA2 //was PINA4 SCL ..... and the communication broke down. Can they be changed? I guess my bitmasks might be wrong...

Thanks, Paul

rambo commented 10 years ago

ATTiny84 has only one hardware USI interface so you cannot run SPI on that while also running I2C. If you're using SPI for output (master) then "bit-banging" is workable (just remember to call TinyWireS_stop_check() between each SPI clock cycle)

ShiftOut is a bit-banged SPI implementation, but due to the need to keep calling TinyWireS_stop_check() you must implent your own (it's very easy though).

paulplpl commented 10 years ago

Hi Eero,

Thanks a lot! I would probably try to implement a bit-banged version of I2C rather than SPI. I receive a lot more data trough SPI and only a fraction of it gets transmitted over I2C. If you happen to have a bit-banged version of TinyWireS I'd greatly appreciate if you could share it.

Thanks, Paul

On Wed, Jul 9, 2014 at 12:14 AM, Eero af Heurlin notifications@github.com wrote:

ATTiny84 has only one hardware USI interface so you cannot run SPI on that while also running I2C. If you're using SPI for output (master) then "bit-banging" is workable (just remember to call TinyWireS_stop_check() between each SPI clock cycle)

ShiftOut is a bit-banged SPI implementation, but due to the need to keep calling TinyWireS_stop_check() you must implent your own (it's very easy though).

— Reply to this email directly or view it on GitHub https://github.com/rambo/TinyWire/issues/10#issuecomment-48437200.

rambo commented 10 years ago

It's still I2C slave that you need ? Master would be easy to bit-bang (if you ignore details like clock-stretching and multi-master conflict resolution) but slave get's complicated, you could try searching for a generic AVR solution (I know there are many bit-banged I2C master libraries but haven't use any so can't recommend one).

What are you building ? A widget that reads SPI sensor (does some calculation) and gives out results over I2C ? I would definitely bit-bang the SPI then and leave USI for I2C. Or switch to attiny1634 (see https://github.com/rambo/arduino-tiny/tree/attiny1634 for arduino support) which has proper TWI slave hardware separate from the USARTs (unfortunately I haven't had the time to write support to TinyWireS for it yet, patches welcome...)

ravipr72 commented 8 years ago

Hi Rambo, I needed 4 PWM pins on 84 and one of them happens to be SDA pin used by TinyWireS. Is there a way to change TinyWireS to use a different pin? thanks, ravi

rambo commented 8 years ago

I don't think so, it uses the USI peripheral so whatever pins that uses you're stuck with, unless you go with some library that has bit-banged I2C slave implementation (I don't know of one).