code:i2c_eeprom
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
code:i2c_eeprom [2008/12/02 09:43] – laurenceb | code:i2c_eeprom [2009/03/20 04:50] (current) – laurenceb | ||
---|---|---|---|
Line 18: | Line 18: | ||
u16 timeout=1; | u16 timeout=1; | ||
TWCR = (1<< | TWCR = (1<< | ||
- | while (!(TWCR & (1<< | + | while (!(TWCR & (1<< |
timeout++; | timeout++; | ||
if(!timeout) | if(!timeout) | ||
Line 31: | Line 31: | ||
u16 timeout=1; | u16 timeout=1; | ||
TWCR = (1<< | TWCR = (1<< | ||
- | while (!(TWCR & (1<< | + | while (!(TWCR & (1<< |
timeout++; | timeout++; | ||
if(!timeout) | if(!timeout) | ||
Line 42: | Line 42: | ||
TWDR = c; | TWDR = c; | ||
TWCR = (1<< | TWCR = (1<< | ||
- | while (!(TWCR & (1<< | + | while (!(TWCR & (1<< |
timeout++; | timeout++; | ||
if(!timeout) | if(!timeout) | ||
Line 50: | Line 50: | ||
} | } | ||
- | u08 i2cread(u08 | + | u08 i2cread(u08 |
{ | { | ||
u16 timeout=1; | u16 timeout=1; | ||
- | TWCR=AK; | + | TWCR=ak; |
while ((!(TWCR & (1<< | while ((!(TWCR & (1<< | ||
timeout++; | timeout++; | ||
Line 94: | Line 94: | ||
datasize--; | datasize--; | ||
i2cstart(); | i2cstart(); | ||
- | i2cwrite(SLA_R|(((*address)>> | + | i2cwrite(SLA_R|((u08)((*address)>> |
for(n=0; | for(n=0; | ||
{ | { | ||
Line 107: | Line 107: | ||
destination[datasize]=i2cread(_NAK_); | destination[datasize]=i2cread(_NAK_); | ||
i2cstop(); | i2cstop(); | ||
+ | (*address)++; | ||
} | } | ||
Line 112: | Line 113: | ||
u32 findtop() // | u32 findtop() // | ||
{ | { | ||
- | u32 top=12*((u32)(((u32)1<< | + | u32 top=12*((u32)1<< |
- | u08 n; | + | u08 n,endcond=TRUE; |
- | u08 endcond=TRUE; | + | u16 place=1<<13; |
- | u16 place=5461; | + | |
for(n=14; | for(n=14; | ||
{ | { | ||
Line 122: | Line 122: | ||
n--; | n--; | ||
else | else | ||
- | endcond=FALSE; | + | endcond=FALSE; |
i2cstart(); | i2cstart(); | ||
i2cwrite(SLA_R); | i2cwrite(SLA_R); | ||
if(i2cread(_NAK_)==MAGIC_NUMBER) // | if(i2cread(_NAK_)==MAGIC_NUMBER) // | ||
- | place& | + | place& |
- | else | + | if(n) |
- | place|=(1<< | + | place|=(1<< |
i2cstop(); | i2cstop(); | ||
if(place> | if(place> | ||
Line 134: | Line 134: | ||
top = 12*( (u32)place ); | top = 12*( (u32)place ); | ||
} | } | ||
+ | set_address(& | ||
+ | i2cstart(); | ||
+ | i2cwrite(SLA_R); | ||
+ | if(i2cread(_NAK_)!=MAGIC_NUMBER) // | ||
+ | place++; | ||
+ | top = 12*( (u32)place ); | ||
return top; | return top; | ||
} | } | ||
Line 141: | Line 147: | ||
u08 magic=MAGIC_NUMBER; | u08 magic=MAGIC_NUMBER; | ||
u32 n=0; | u32 n=0; | ||
- | set_address(& | + | for(; |
- | for(; | + | |
{ | { | ||
- | / | + | /* |
+ | set_address(& | ||
i2cwrite(magic); | i2cwrite(magic); | ||
if((u08)n> | if((u08)n> | ||
Line 151: | Line 157: | ||
_delay_loop_2( (u16) ( (float)F_CPU*0.006/ | _delay_loop_2( (u16) ( (float)F_CPU*0.006/ | ||
}*/ | }*/ | ||
- | if(!((u08)n)) | + | if(!((u08)n)) // |
{ | { | ||
i2cstop(); | i2cstop(); |
code/i2c_eeprom.1228211006.txt.gz · Last modified: 2008/12/02 09:43 by laurenceb