Hallo! Ich sitze hier in Finnland und sollte für ein Projekt Temperaturmessungen mit einem AVR 90S2313 und dem Dallas DS1820 machen. Prinzipiell eigentlich kein Problem aber bei mehreren Sensoren funktioniert die Temperaturabfrage nur beim 1.Mal, danach gibt es nur noch das Error-Signal. Irgendwie gehen die Adressen verloren, vermute ich. Ich programmiere mit dem CodevisionAVR in C. Hier der Sourcecode: /*************************************************** Project : LCD Temperature Display Version : 1.2 Date : 06.11.2006 Author : Florian Hämmerle Displays the temperature value of a ds1820 sensor on a 16x2 lcd display and in a terminal window on computer by serial communication ***************************************************/ //LCD Module connected to PORTB //Temperature Sensor conntected to PORTD BIT6 ! #asm .equ __lcd_port=0x18 .equ __w1_port=0x12 .equ __w1_bit=6 #endasm #include <90s2313.h> //Chip #include <ds1820.h> //Temerature Sensor #include <delay.h> //timer library #include <math.h> //math library #include <stdio.h> //standard in and output (serial communication) #include <stdlib.h> //int to string #include <string.h> //string concatenate #include <lcd.h> //LCD-Display #define xtal 8000000L //Quarz frequency #define baud 9600 //Baud Rate #define MAX_DEVICES 5 //Max number of Devices connected to the bus unsigned char rom_codes[MAX_DEVICES][9]; void main(void) { int temp,rem; //variable for temperature and remain of division char *str_temp[5],*str_rem[2]; //string for temperature and remain char *str="."; //komma char *deg="_Celsius"; //string char length,i,devices,j; //variable for stringlength and number of devices char *pt; UBRR=xtal/16/baud-1; //initialize the UART's baud rate UCR=0x18; //initialize the UART control register RX & TX enabled, no interrupts, 8 data bits lcd_init(16); //16 columns LCD Display devices=w1_search(0xf0,rom_codes); //get number of devices connected to the bus and store rom-codes while (1) { for (j=0;j<devices;j++){ temp=ds1820_temperature_10(&rom_codes[j][0]); //read temperature sensor rem=abs(temp%10); //rest of division by 10 (value after comma) temp=temp/10; //temperature value itoa(temp,str_temp); //convert int into string itoa(rem,str_rem); //convert int into string pt=strcat(str_temp,str); //add komma to temperature pt=strcat(pt,str_rem); //add remain pt=strcat(pt,deg); //add "Celsius" length=strlen(pt); //get total length of string //Serial output for(i=0;i<length;i++){ putchar(*(pt+i)); } putchar('\r'); //LCD output lcd_clear(); for(i=0;i<length;i++){ lcd_gotoxy(i,1); lcd_putchar(*(pt+i)); } delay_ms(1000); //wait for 1000ms } } } Es sollte also immer die Temperatur eines Sensors nach dem anderen ausgegeben werden. Beim ersten Mal durchlaufen der Schleife funktionieren alle Werte. Danach kommen nur noch -9999, was soviel wie das Error-Signal bedeutet. Komischerweise funktioniert, wenn ich 3 Sensoren anschließe, einer noch... Ich versteh es überhaupt nicht und wäre froh, wenn mir jemand einen Rat geben könnte.
Also ich habe das Problem jetzt gelöst. Ich weiß zwar nicht an was es gelegen ist aber ich habe alles neu programmiert und besser strukturiert und es funktioniert perfekt! Viel Spaß damit!
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.