AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein I2C BUS LM75A Temperatur sensor Problem
Thema durchsuchen
Ansicht
Themen-Optionen

I2C BUS LM75A Temperatur sensor Problem

Ein Thema von yacdrak · begonnen am 10. Apr 2021 · letzter Beitrag vom 10. Apr 2021
Antwort Antwort
yacdrak

Registriert seit: 22. Dez 2020
7 Beiträge
 
#1

I2C BUS LM75A Temperatur sensor Problem

  Alt 10. Apr 2021, 10:40
Moin zusammen,
Ich versuche Temperatur aus der LM75A Sensor zu lesen. Ich bekomme immer das gleiche Problem : Ausgabe 253. könnte jemand mir helfen bitte ? danke.
Anhang finden Sie mein Quellcode.
Delphi-Quellcode:
unit Unit1;

interface


uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs , i2cusb, Vcl.StdCtrls, Vcl.ComCtrls;


const
cTimeoutInMs = 1000;
cTimeoutInit = 5000;

type
  TArray = array[0..7] of Integer;
  TByteArr = array of byte;
  TForm1 = class(TForm)
  Button1: TButton;
  StatusBar1: TStatusBar;
  Label1: TLabel;

  procedure Button1Click(Sender: TObject);


  private
    { Déclarations privées }
  public


  end;

   function start_i2c ( address : Integer ):ShortInt;
  function stop_i2c():ShortInt;
  function slave_port( address: TArray): ShortInt;
  function ACK_device():ShortInt;
  function No_ACK():ShortInt;
 Function temperature_LM75_lesen():TArray;
 function Integer_To_Byte(str: String):TByteArr;
 function write( Wert : TArray ):ShortInt;
 function read():TArray;


var
  Form1: TForm1;
  ic : Ti2cUsb;
  Temperatur1 : Byte;
  Temperatur2 : Byte;
  Wert : Double ;
  Byte1, Byte2 :Byte;
  a : Double;
  write_add_temp : TArray = (1,0,0,1,0,0,1,0);
  read_add_temp : TArray = (1,0,0,1,0,0,1,1);
  write_add_pca : TArray = (0,1,0,0,1,1,1,0);
  read_add_pca : TArray = (0,1,0,0,1,1,1,1);
  init_temp : TArray = (0,0,0,0,0,0,0,0);
  pointer_Byte : TArray = (0,0,0,0,0,0,0,1);

implementation

     {$R *.dfm}



function slave_port( address : TArray): ShortInt;
var i:ShortInt;
begin
    for i := 0 to 7 do
   begin
   if address[i] = 1 then
   begin
   ic.wr_byte_port(1); //SDA = 1 SCL = 0
   ic.wr_byte_port(0); //SDA = 1 SCL = 1
   end
   else
   begin
   ic.wr_byte_port(3); //SDA = 0 SCL = 0
   ic.wr_byte_port(2); //SDA = 0 SCL = 1
   end;
   end;
   Result := 0;
end;

function start_i2c ( address : Integer ):ShortInt;
begin

  ic.wr_byte_port(0); //SDA = 1 ; SCL = 1
  ic.wr_byte_port(2); //SDA = 0 ; SCL = 1

   if address = 146 then
   begin
     slave_port(write_add_temp);
   end
   else if address = 147 then
   begin
     slave_port(read_add_temp);
   end
   else if address = 78 then
   begin
     slave_port(write_add_pca);
   end
   else if address = 79 then
   begin
     slave_port(read_add_pca);
   end;
   Result := 0;
end;



function No_ACK():ShortInt;
begin
   ic.wr_byte_port(1); //SDA = 1 SCL = 0
   ic.wr_byte_port(0); //SDA = 1 SCL = 1
   ic.wr_byte_port(3); //SDA = 0 SCL = 0
   Result := 0;
end;

function ACK_device():ShortInt;
begin
    ic.wr_byte_port(3); //SDA = 0 SCL = 0
   ic.wr_byte_port(2); //SDA = 0 SCL = 1
   ic.wr_byte_port(3); //SDA = 0 SCL = 0
   Result := 0;
end;


function stop_i2c():ShortInt;
begin
  ic.wr_byte_port(3); //SDA = 0 SCL = 0
  ic.wr_byte_port(0); //SDA = 1 ; SCL = 1
  Result := 0;
end;





Function temperature_LM75_lesen():TArray; //Liest einen Wert (1 Byte) vom LM75 Temperatursensor
var
 i:ShortInt;
 value:Byte;
 arr:TArray;
begin

       for i := 7 downto 0 do
       begin
           ic.wr_byte_port(1);
           ic.wr_byte_port(0);
           ic.rd_byte_port(value);
          arr[i] := value;


       end;

 Result := arr;


end;





function Integer_To_Byte(str: String):TByteArr;
var
i: integer;
begin
SetLength(Result, Length(str));
for i := 0 to length(str)-1 do
  Result[i] := ord(str[i+1]) -48;
end;




function write( Wert : TArray ):ShortInt;
var

myByte : TArray;
i : ShortInt;
begin
myByte := Wert;// Integer_To_Byte(Wert);

   for i := 0 to 7 do
   begin
   if myByte[i] = 1 then
   begin
   ic.wr_byte_port(1); //SDA = 1 SCL = 0
   ic.wr_byte_port(0); //SDA = 1 SCL = 1
   end
   else
   begin
   ic.wr_byte_port(3); //SDA = 0 SCL = 0
   ic.wr_byte_port(2); //SDA = 0 SCL = 1
   end;
   end;
Result := 0;
end;

function read():TArray;
 var
 i:ShortInt;
 value:Byte;
 arr : TArray;
begin

       for i := 7 downto 0 do
       begin
           ic.wr_byte_port(1);
           ic.wr_byte_port(0);
           ic.rd_byte_port(value);
             arr[i] := value;

       end;

 Result := arr;
 end;




procedure TForm1.Button1Click(Sender: TObject);

 var
 val1 : TArray;
 val2 : TArray;
 Value : double ;
 begin
 //Register Temp configurate
 ic := Ti2cUsb.Create;
 ic.Init(10);
 start_i2c(146);
 ACK_device;
 write(pointer_Byte);
 //ACK_device;
 //write(init_temp);
 No_ACK;
 stop_i2c;
 //Read Temp register with preset Pointer (2 Byte Data)
 start_i2c(147);
 ACK_device;
 val1 := temperature_LM75_lesen;
 ACK_device;
 val2 := temperature_LM75_lesen;
 No_ACK;
 {
  If (val1 And 128) = 0 Then
    begin
        Value := val1              //Temperatur Vorkomma >= 0°C
    end
    else
    begin
        Value := val1 - 255;        //Temperatur Vorkomma < 0°C
    end;
    If ((val2 And 128) <> 0) Then
        begin
        Value := Value + 0.5;
        end;
   }


 stop_i2c();

      ShowMessage(val1[0].ToString);
      ShowMessage(val2[1].ToString);
 end;

End.
Miniaturansicht angehängter Grafiken
capture-1.jpg   capture-2.jpg  
Angehängte Dateien
Dateityp: txt delphi i2c test.txt (4,9 KB, 9x aufgerufen)
  Mit Zitat antworten Zitat
generic

Registriert seit: 24. Mär 2004
Ort: bei Hannover
2.415 Beiträge
 
Delphi XE5 Professional
 
#2

AW: I2C BUS LM75A Temperatur sensor Problem

  Alt 10. Apr 2021, 19:51
Es gab vor kurzen einen ähnlichen Beitrag:
https://www.delphipraxis.net/206446-...75-sensor.html
Coding BOTT - Video Tutorials rund um das Programmieren - https://www.youtube.com/@codingbott
  Mit Zitat antworten Zitat
yacdrak

Registriert seit: 22. Dez 2020
7 Beiträge
 
#3

AW: I2C BUS LM75A Temperatur sensor Problem

  Alt 10. Apr 2021, 20:50
Hallo,
Das ist auch mein Betrag aber leider habe ich keine Lösung gefunden. Ich habe noch änderung gemacht.
  Mit Zitat antworten Zitat
yacdrak

Registriert seit: 22. Dez 2020
7 Beiträge
 
#4

AW: I2C BUS LM75A Temperatur sensor Problem

  Alt 10. Apr 2021, 20:50
Delphi-Quellcode:
 //Register Temp configurate
 ic := Ti2cUsb.Create;
 ic.Init(3);
 start_i2c(144);
 ACK_Slave;
 write(init_temp);
 ACK_Slave;
 stop_i2c;


 //Read Temp register with preset Pointer (2 Byte Data)
 start_i2c(145);
 ACK_Slave;
 val1 := temperature_LM75_lesen;
 ACK_Master;
 val2 := temperature_LM75_lesen;
 No_ACK_Master;
 stop_i2c;
  Mit Zitat antworten Zitat
Antwort Antwort

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:50 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz