LM-75 Temperatur auslesen
-
Hallo,
ich habe ein wahnsinniges Problem und ihr seit meine letzte Chance ich habe wirklich schon alles probiert und auch schon alles im Internet gelesen was es darüber zu lesen gibt.
Also ich möchte die Temperatur mit Hilfe des LPT Port auslesen und dann das ganze in eine Datei schreibe, ist ja auch alles kein Problem aber der LM-75 liefert mir immer 0 °C, was natürich schlecht ist.
Den Sensor habe ich nach dieser Anleitung zusammengebaut http://www.franksteinberg.de/lm75.htm .
Jetzt zum Quelltext, ich habe einen Borland Compiler genutzt und die Ansteuerung des LPT Ports mit Hilfe der inpout32.dll gemacht.
Es werden Daten auch ohne Probleme an die Pins ausgegeben aber der Acknowladge bleibt immer auf hicgt ist das normal?, denn auch wenn ich nichts angeschlossen habe sehe ich mit deinem Mnitoring Programm das die Import Pis immer auf hight sind.
DAs Problem befindet sich wahrscheinlich in der Funktion ab Zeile 308.
Ich wäre für eure Hilfe sehr dankbar.Nico Vollmer
/* +----------------------------------------------------------------------+ */ /* |+--------------------------------------------------------------------+| */ /* || Portprogramming & File Operations with ANSI C || */ /* |+--------------------------------------------------------------------+| */ /* || Project: ......................... Wind and Temperatur || */ /* || File: ............................ LM75 Control Capture.cpp || */ /* || Version: ......................... 0.9b || */ /* || Compiler: ........................ Borland C++BuilderX || */ /* || || */ /* |+------------------------------------------------------------------- +| */ /* || Members: ......................... Nico V., Matthias W. || */ /* || Copyright: ....................... Minimalist GNU for Windows || */ /* || Comment: All credits related to the inpout32.dll to it's Author! || */ /* |+--------------------------------------------------------------------+| */ /* +----------------------------------------------------------------------+ */ /* |+--------------------------------------------------------------------+| */ /* || Explanations: || */ /* || 1. "errorlevel == 0" means there is NO ERROR! || */ /* || 2. Normally we try to structure the code chronologically, the || */ /* || cause of the csvfile functions at the begining is a || */ /* || prototyping issue which occures at an interactive function. || */ /* || 3. We had to exclude the input of the path into the main(), || */ /* || because of a array issue that occured in order of array returns || */ /* || out of a function. || */ /* |+--------------------------------------------------------------------+| */ /* +----------------------------------------------------------------------+ */ #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #include <windows.h> #include <time.h> #define PPORT_BASE 0x378 #define DATA_REGISTER PPORT_BASE+0 #define STATUS_REGISTER PPORT_BASE+1 #define CONTROL_REGISTER PPORT_BASE+2 #define BYTE 8 #define CYCLES_FOR_MEAN 5 #define PATH_AND_FILENAME 50 #define STRING 80 #define LM75_TIME 10 #define WIND_TIME 50 #define PI 3.141592654 #define WD_IN 16 //Byte for WIND #define WD_RD 0.007 //Radius of WIND in m #define WD_CONST 0 //Const. value for windspeed #define CURRENT_LM75 128 //Current for LM75 #define CURRENT_WIND 32 //Current for WIND #define D_IN 64 //Byte for SDA -> ACKNOWLEDGE high #define CH_DH 0 //Byte for STROBE -> SCL high / AUTO FEED -> SDA high #define CL_DH 1 //Byte for STROBE -> SCL low / AUTO FEED -> SDA high #define CH_DL 2 //Byte for STROBE -> SCL high / AUTO FEED -> SDA low #define CL_DL 3 //Byte for STROBE -> SCL low / AUTO FEED -> SDA low struct tm * tmnow; typedef short( _stdcall * inpfuncPtr ) ( short portaddr ); typedef void( _stdcall * oupfuncPtr ) ( short portaddr, short datum ); inpfuncPtr inp32fp; oupfuncPtr oup32fp; short Inp32( short portaddr ) { return ( inp32fp )( portaddr ); } void Out32( short portaddr, short datum ) { ( oup32fp )( portaddr, datum ); } void func_loadlib() { HINSTANCE hLib; hLib = LoadLibrary( "inpout32.dll" ); if ( hLib == 0 ) { fprintf( stderr, "LoadLibrary -inpout32.dll- Failed!\n" ); fflush( stdin ); getch(); } inp32fp = ( inpfuncPtr )GetProcAddress( hLib, "Inp32" ); if ( inp32fp == 0 ) { fprintf( stderr, "Failure! GetProcAdress for Inp32 Failed.\n" ); fflush( stdin ); getch(); } oup32fp = ( oupfuncPtr )GetProcAddress( hLib, "Out32" ); if ( oup32fp == 0 ) { fprintf( stderr, "Failure! GetProcAdress for Oup32 Failed.\n" ); } } void create_csvfile( char matrix_path_and_filename[PATH_AND_FILENAME] ) { FILE * datei; datei = fopen( matrix_path_and_filename, "w+" ); fclose( datei ); } int write_value_to_csvfile( char matrix_path_and_filename[PATH_AND_FILENAME], double value ) { FILE * datei; int errorlevel = 0; time_t tnow; time( & tnow ); tmnow = localtime( & tnow ); datei = fopen( matrix_path_and_filename, "a" ); fprintf( datei, "%i.%i.%i;%i.%i.%i;%.1lf;;\n", tmnow->tm_mday, tmnow->tm_mon + 1, tmnow->tm_year + 1900, tmnow->tm_hour, tmnow->tm_min, tmnow->tm_sec, value ); if ( datei == NULL ) { errorlevel = 1; fclose( datei ); return errorlevel; } else { fclose( datei ); return errorlevel; } } void write_string_to_csvfile( char matrix_path_and_filename[PATH_AND_FILENAME] ) { FILE * datei; char string[STRING]; datei = fopen( matrix_path_and_filename, "a" ); printf( "\nPlease Input String: " ); fflush( stdin ); gets( string ); fprintf( datei, "%s\n\n\n", string ); fclose( datei ); } char interactive_choice_and_prove() { int counter_prove = 0; char choice[1]; do { printf( "\n\nInput [Yes or No]: " ); fflush( stdin ); counter_prove = scanf( "%1[yYnN]", choice ); if ( counter_prove != 1 ) { printf( "False input!!" ); Sleep( 1000 ); } } while ( counter_prove != 1 ); return ( choice[0] ); } void interactive_introduction( char matrix_path_and_filename[PATH_AND_FILENAME]) { char choice; create_csvfile( matrix_path_and_filename ); printf( "\n\nWould you like to comment the file?\n"); choice = interactive_choice_and_prove(); if ( choice == 'y' || choice == 'Y' ) { write_string_to_csvfile( matrix_path_and_filename ); } } int interactive_input() { int input, counter_prove; do { fflush( stdin ); counter_prove = scanf( "%i", & input ); if ( counter_prove != 1 ) { printf( "\nFalse input!!\n" ); } } while ( counter_prove != 1 ); return ( input ); } int interactive_number_of_cycles() { int value_cycles; printf( "\n\nHow many cycles do you want to do?\n(One cycle == 1 minute)\n" ); value_cycles = interactive_input(); return value_cycles; } void func_stop() { Out32( CONTROL_REGISTER, CH_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); } void func_start() { Out32( CONTROL_REGISTER, CH_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); } void func_send_adress_byte() { int counter; Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); for ( counter = 0; counter < 2; counter++ ) { Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); } Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); for ( counter = 0; counter < 3; counter++ ) { Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); } Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); } void func_slave_acknowledge() { Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); } int in_the_power_of( int x, int n ) { if ( n == 0 ) { return ( 1 ); } else return ( in_the_power_of( x, n - 1 ) * x ); } int func_slave_send_data_a() { int counter, n = 7; int value_byte = 0; Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); for ( counter = 0; counter < BYTE; counter++ ) { Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); if ( Inp32( STATUS_REGISTER ) & D_IN ) { value_byte = value_byte + in_the_power_of( 2, n ); } n--; Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); } return value_byte; } int func_slave_send_data_b() { int value_bit; Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); if ( Inp32( STATUS_REGISTER ) & D_IN ) { value_bit = 1; } Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); return value_bit; } void func_master_acknowledge() { Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DL ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); } void func_master_no_acknowledge() { Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CH_DH ); Sleep( 10 ); Out32( CONTROL_REGISTER, CL_DH ); Sleep( 10 ); } double get_temperature( int value_byte, int value_bit ) { double temperature; if ( value_byte >= 128 ) { temperature = value_byte - 256; } else temperature = value_byte; if ( value_bit == 1 ) { temperature = temperature + 0.5; } return temperature; } double get_average_temperature( double temperature[CYCLES_FOR_MEAN] ) { int counter; double average_temperature = 0.0; for ( counter = 0; counter < 5; counter++ ) { average_temperature = average_temperature + temperature[counter]; } for ( counter = 0; counter < 5; counter++ ) { if ( average_temperature - 10.0 > temperature[counter] || average_temperature + 10.0 < temperature[counter] ) { temperature[counter] = average_temperature; } } average_temperature = 0.0; for ( counter = 0; counter < 5; counter++ ) { average_temperature = average_temperature + temperature[counter]; } return average_temperature; } int main() { time_t start; char matrix_path_and_filename[PATH_AND_FILENAME]; int counter_a, counter_b, counter_c, value_cycles; int data_from_slave_a, data_from_slave_b, errorlevel = 0; double temperature[CYCLES_FOR_MEAN], average_temperature; func_loadlib(); printf( "Welcome to the data capture programm for LM75 a.o.!\n\n\nWhat should be the name of the path and the file in which the data will be \ncaptured?\n\n" "Syntax: 'C://test_folder//from_a_to_z.csv' [max 50 characters]\nNote: If your input is against" " syntax you will probably crash the application!\n\nInput please: " ); gets( matrix_path_and_filename ); interactive_introduction( matrix_path_and_filename); value_cycles = interactive_number_of_cycles(); func_start(); for ( counter_c = 0; counter_c < value_cycles; counter_c++ ) { time( & start ); for ( counter_b = 0; counter_b < CYCLES_FOR_MEAN; counter_b++ ) { Out32( PPORT_BASE, CURRENT_LM75 ); func_stop(); func_send_adress_byte(); func_slave_acknowledge(); data_from_slave_a = func_slave_send_data_a(); func_master_acknowledge(); data_from_slave_b = func_slave_send_data_b(); func_master_no_acknowledge(); Out32( PPORT_BASE, CURRENT_WIND ); temperature[counter_b] = get_temperature( data_from_slave_a, data_from_slave_b ); } average_temperature = get_average_temperature( temperature ); printf( "\n%i LM75", counter_c + 1 ); errorlevel = write_value_to_csvfile( matrix_path_and_filename, average_temperature ); if ( errorlevel == 1 ) { counter_c--; } if ( errorlevel != 1 ) { } } printf( "\n\nOperation successful!\n" ); fflush( stdin ); getch(); return 0; }
-
Hi Bruder !
Würd dir ja gern helfen, aber ich habe diesen Sensor nicht.
Vielleicht ist deiner auch kaputt ?
Gruß,
B.B.
-
-
^^
den ganzen link kopieren und in die browser-leiste pasten. der filter ist wichtig.
-
hi,
ich dachte auch zuerst, das er kanputt sei, aber dann habe ich noch einen bestellt und gaz vorsichtig zusammengehötet.
Außerdem ist auf dem Osziluskop auch was am Acknowledge zu sehen, also ich gehe davon aus, das er diesmal auf jedenfall heile ist.
Nico