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/04 04:44] – 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 113: | 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 123: | 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 135: | 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; | ||
} | } |
code/i2c_eeprom.1228365888.txt.gz · Last modified: 2008/12/04 04:44 by laurenceb