Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

i2c read and write problem in avr atmega8.

Status
Not open for further replies.

abilashjoseph

Member level 1
Joined
Sep 8, 2009
Messages
34
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Kerala
Activity points
1,560
hi,
I am using atmega8 to interface i2c(TWI), i am a beginner in I2C. from my knowledge I wrote a code,
that is given below. but i don't get any response or status,

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/twi.h>

void twi_init(void)
{

TWBR = 32;

TWCR = (1<<TWEN);
}

void twi_start(void)
{


TWCR = (TWCR & 0x0f) | (1<<TWINT)|(1<<TWSTA);
}

int main(void)
{
DDRC = 0xff;
twi_init();
twi_start();
}

is this code is correct?, any other codes are needed?
please help.
thanks .
 

What device are you attempting to access using the I2C bus?

It is difficult to give you advice without know exactly what I2C device you are attempting to access.

Your code appears to lacking several important steps to both initialize and access the device in question.

Here is a tutorial demoing the access of several different I2C devices:

How to use I2C-bus on the Atmel AVR Microcontroller

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top