|
|
View previous topic :: View next topic |
Author |
Message |
bubbi Guest
|
DS1616 temperature |
Posted: Sat Jul 10, 2004 11:51 am |
|
|
Hi there,
I can't read the temperature out of this IC.
My functions always return 0.
Can anyone give me a hint?
Thanks
My code:
Code: |
#include "TempLogger.h"
#define TMP_SCLK PIN_B1
#define TMP_IO PIN_B3
#define TMP_RST PIN_B2
BYTE temperatur=0;
char c;
BYTE read_ds1616(BYTE cmd) {
BYTE i,data;
output_high(TMP_RST);
write_ds1616_byte(cmd);
for(i=0;i<=7;++i) {
shift_right(&data,1,input(TMP_IO));
output_high(TMP_SCLK);
delay_us(2);
output_low(TMP_SCLK);
delay_us(2);
}
output_low(TMP_RST);
return(data);
}
BYTE TMP_get_temp() {
BYTE temp;
temp = read_ds1616(0x55); // Get Temperature
return(temp);
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(1)
{
zeichen=getch();
if (c=='2') {
printf("HiThere\n\r");
}
if (c=='1') {
temperatur=TMP_get_temp();
printf("temp: %i\n\r",temperatur); //output RS232
}
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jul 11, 2004 9:53 pm |
|
|
Look at the source code posted on this page:
http://sjeffroy.free.fr/GBF_num_/DS1615_-_DS1616/ds1615_-_ds1616.html
Especially look at the code for this function:
ds1616_temp()
Notice he is doing two things that you are not doing:
1. He tests the CS0 bit in the Control 2 register. If the CS0 bit
is not = 1, then he sets it = 1.
2. He sends the command (0x55) to read the temperature.
But before he reads the temperature value, he checks the DR
bit in the Status 1 register. When DR = 1, then he reads the
temperature.
If you make these two changes to your code, it will probably work.
---- |
|
|
bubbi Guest
|
|
Posted: Mon Jul 12, 2004 4:04 am |
|
|
Thanks !!!
This page helps me a lot |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|