[En-Nut-Discussion] DS1620 temp sensor

Sigurd Kleppan 021243 at student.hit.no
Wed Feb 11 13:50:36 CET 2004


In my project with Ethernut i want to log som temperatures. I use DS1620 and to get the temp. I have to send 0xAA to the device. Then i get the temp back. 
I have written a code to send the data, but it is not working. Can you see some error and give me some hints on whats wrong in the Get1620byte and Put1620byte functions please. 

Do you know someone who have written code for DS1620 i Ethernut? 

Thank you! 

Sigurd 

//THE TEMPERATURE CODE 

unsigned char Get1620byte( void ) 
{ 
unsigned char j,k=0,b=1; 
outp(0x00,DDRB);
outp(0x00,PORTB); 

for (j=0; j<8; j++) 
{ 
cbi(PORTB,0); //CLK=0; 
if (bit_is_set(PINB, 3)){ k|=b;} 
sbi(PORTB,0); //CLK=1; 
b=(b<<1); /* Setup for next read and or */ 
} 
cbi(PORTB,0); 
cbi(PORTB,3); 
return k; 
} 


unsigned char Put1620byte(unsigned char m) 
{ 
unsigned char k,b=1; 
unsigned char DQ; 
outp(0xFF,DDRB);
cbi(PORTB,0); 
cbi(PORTB,3); 
sbi(PORTB,5); //RST=1; 
for (k=0; k<8; k++) 
{ 
cbi(PORTB,0); //CLK=0; 
DQ[k] = (m & b); 
if(!DQ==0){ 
sbi(PORTB,3);} 
else{cbi(PORTB,3);} 
sbi(PORTB,0); //CLK=1; 
b=(b<<1); /* Setup to send next bit */ 
} 
cbi(PORTB,0); 
cbi(PORTB,3); 


return 0; 
} 

void main(){ 

sbi(PORTB,5); // RST=1; 
Put1620byte(0xAA)); 
temp_and_half_bit = Get1620byte(); /* read 1st byte of temp */ 
sign_bit = Get1620byte(); /* read 2nd byte of temp */ 
cbi(PORTB,5); 
fprintf(stream,"%d",temp_and_half_bit); 

} 








More information about the En-Nut-Discussion mailing list