Re: Procyon Library for Atmel AVR MCU - I²C problems
- From: Vladimir Vassilevsky <antispam_bogus@xxxxxxxxxxx>
- Date: Wed, 30 Jul 2008 11:14:56 -0500
Rüdiger Leibrandt wrote:
Hello!
I am new to programming and am struck with the Manual for the Procyon
Library for Atmel's ATMega MCUs. It basically provides functions for all
the interfaces and functions available on the Atmel MCUs.
[...]
I guess I have a conceptual error in understanding the I²C Protocol and / or
utilizing the Procyon Library.
The conceptual error is in multiplying the entities beyond the
necessity. For something as simple as AVR (tm), you don't need any libraries, and the only manual required is the AVR data***. All it takes to run I2C is to program a couple of registers.
The program compiles without problems under avr-gcc.
Any sggestions and hints welcome!
As simple as that:
static void I2C_WaitDone(void)
{
while(!(TWCR&0x80));
}
static void I2C_Stop(void)
{
TWCR = 0x94;
while(TWCR&0x10);
}
static void I2C_Start(void)
{
TWCR = 0xA4;
I2C_WaitDone();
}
static void I2C_Transmit_Byte(u8 byte)
{
TWDR = byte;
TWCR = 0x84;
I2C_WaitDone();
}
//=======================
void I2C_Action(u8 address, u8 *data, u8 length)
{
u8 ci;
I2C_Start();
I2C_Transmit_Byte(address);
if(address & 0x01) // I2C read
{
for(ci = 0; ci < length; ci++)
{
if(ci < (length - 1)) TWCR = 0xC4; // Confirm byte with ACK
else TWCR = 0x84; // Last byte - send NAK
I2C_WaitDone();
data[ci] = TWDR;
}
}
else // I2C write
{
for(ci = 0; ci < length; ci++) I2C_Transmit_Byte(data[ci]);
}
I2C_Stop();
}
//----------------------------------
Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
.
- Follow-Ups:
- Re: Procyon Library for Atmel AVR MCU - I²C problems
- From: Rüdiger
- Re: Procyon Library for Atmel AVR MCU - I²C problems
- References:
- Procyon Library for Atmel AVR MCU - I²C problems
- From: Rüdiger Leibrandt
- Procyon Library for Atmel AVR MCU - I²C problems
- Prev by Date: Re: Recommendations for a Quadrature Decoder IC or MicroController
- Next by Date: Re: arm9e: how do I invert sign of a halfword?
- Previous by thread: Procyon Library for Atmel AVR MCU - I²C problems
- Next by thread: Re: Procyon Library for Atmel AVR MCU - I²C problems
- Index(es):