[En-Nut-Discussion] TWI Initialisation

Peter Sodermanns peter.sodermanns at aixcon.de
Thu Feb 9 15:48:18 CET 2006


Back to my initial problem:

> TWINT in register TWCR is not set,
> interrupt routine is never executed,
> no signals at output pins.

I put some debug output in TwInit:

int TwInit(u_char sla)
{
#ifndef __AVR_ENHANCED__
     return -1;
#else
     u_long speed = 2400;
     printf_P(PSTR("TwInit called\n"));
     if (NutRegisterIrqHandler(&sig_2WIRE_SERIAL, TwInterrupt, 0)) {
         return -1;
     }
     /*
      * Set address register, enable general call address, set transfer
      * speed and enable interface.
	*/
     outb(TWAR, (sla << 1) | 1);
     TwIOCtl(TWI_SETSPEED, &speed);
     printf_P(PSTR("1 TWCR = %d\n"), TWCR);
     outb(TWCR, _BV(TWINT));
     printf_P(PSTR("2 TWCR = %d\n"), TWCR);
     outb(TWCR, _BV(TWEN) | _BV(TWIE));
     printf_P(PSTR("3 TWCR = %d\n"), TWCR);
     /*
      * Initialize mutex semaphores.
      */
     NutEventPost(&tw_mm_mutex);
     printf_P(PSTR("TwInit finished\n"));
     return 0;
#endif /* __AVR_ENHANCED__ */
}

resulting in:

Nut/OS:       4.0.2.1
...
TwInit called
1 TWCR = 0
2 TWCR = 0
3 TWCR = 5
TwInit finished

(Updating Nut/OS didn't change things...)

Is it wrong to expect "TWCR = 128" after the command "outb(TWCR, 
_BV(TWINT));"?
Why is the TWINT-bit not set?
And why are there no signals at all at ports D0/D1? At least a start 
condition and sending of slave address I would have expected.


Any ideas?


Regards
               Peter



More information about the En-Nut-Discussion mailing list