avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] Atmega165 USI I2C (TWI)


From: Grant Elliott
Subject: [avr-chat] Atmega165 USI I2C (TWI)
Date: Fri, 15 Jul 2005 21:00:18 -0400

I've been trying to get I2C master to work on an Atmega165 using the USI. I started with Atmel Appnote AVR310 intended for IAR EWAAVR, but I would prefer to use AVRGCC. The changes I made are:

1) Replaced __delay_cycles with _delay_loop_1 from delay.h. (and divided the times by 3, since each tick to _delay_loop_1 takes three clock cycles.)
2) Added a set of Atmega165 definitions (identical to Atmega169)

#define DDR_USI             DDRE
#define PORT_USI            PORTE
#define PIN_USI             PINE
#define PORT_USI_SDA        PORTE5
#define PORT_USI_SCL        PORTE4
#define PIN_USI_SDA         PINE5
#define PIN_USI_SCL         PINE4

3) Removed the __x from the declaration of USI_TWI_Start_Transceiver_With_Data. Honestly, I don't even know what __x does, but AVR GCC didn't like it.

4) Commented out the lines that set SCL and SDA as outputs. With them present, the lines don't pull high as expected after initialization. Further, an attempt to use the transceiver stalls because the lines never change state.

Whenever I perform any transfer, I get 6 from USI_TWI_Get_State_Info(), corresponding to missing an acknowledge after the address. I don't have a scope handy, but my multimeter clearly shows the lines rising and falling during the transmission.

If anyone has any advice (I'm mostly concerned with items 3 and 4 above) or has an I2C Master USI library, I'd appreciate it. Thanks a lot.

 - Grant





reply via email to

[Prev in Thread] Current Thread [Next in Thread]