fredericplante/sanguino

TWI does not twi_init() correctly in wire/utility/twi.c for atmega644[p]

Closed this issue · 2 comments

I know this is not an "Arduino" forum.  I tried opening an issue there but
it was rejected as unsupported processor.  Thought I'd open it here for
people to see.  The code was defaulting to PORTD,0/1 for the pullup
resistors for TWI, where the 644[p] is actually PORTC 0/1

ref: http://code.google.com/p/arduino/issues/detail?id=238

In the arduino/hardware/libraries/Wire/utility directory I had to modify
twi_init() in twi.c 
twi_init does not include a definition for the atmega644[p] and such
incorrectly set's the pull up registers for the wrong ports.
The atmega644[p] TWI are ports PORTC0/PORTC1 not PORTD0/PORTD1 as the
source states.

I added:
  #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
    sbi(PORTC, 0);
    sbi(PORTC, 1);
 to 

void twi_init(void)
{
  // initialize state
  twi_state = TWI_READY;

  #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__) ||
defined(__AVR_ATmega328P__)
    // activate internal pull-ups for twi
    // as per note from atmega8 manual pg167
    sbi(PORTC, 4);
    sbi(PORTC, 5);
  #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
    sbi(PORTC, 0);
    sbi(PORTC, 1);
  #else
    // activate internal pull-ups for twi
    // as per note from atmega128 manual pg204
    sbi(PORTD, 0);
    sbi(PORTD, 1);
  #endif

I am running Arduino version 0017.

Original issue reported on code.google.com by sancho...@gmail.com on 3 May 2010 at 9:43

I can confirm that external pullup resistors are necessary on the sanguino with 
this
software configuration. I had assumed it was a hardware issue.

Original comment by bruce.g....@gmail.com on 6 May 2010 at 12:13

not sure about 644p, but on the 1284p you can enable the internal pullups.  I 
have them turned on for 1284p and 644p in 0023r3

Original comment by sutt...@gmail.com on 19 Feb 2012 at 10:29

  • Changed state: Fixed