2

I'm trying to read and write bytes in an i2c bus using LM75 and a Master (USB ITS). Using a library from Github (AsyncPro for VCL 1.7) and Delphi .

The problem I always get, that i receive 253 or 255 when I compile to project and try to read the first Byte and the second MSB LSB. Please can someone help me ? and thank you the function used to set up SCL and SDA is wr_byte_port() with parameter

  • 0 : SDA= 1 SCL= 1
  • 1 : SDA= 1 SCL= 0
  • 2 : SDA= 0 SCL= 1
  • 3 : SDA= 0 SCL= 0

Write LM75 Register Read temp`

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 Byte;
  TArray11 = array[0..10] of Byte;
  TByteArr = array of byte;
  TForm1 = class(TForm)
  Button1: TButton;
  StatusBar1: TStatusBar;
  Label1: TLabel;

  procedure Button1Click(Sender: TObject);


  private
    {  }
  public


  end; 
var
  Form1: TForm1;
  ic : Ti2cUsb;
  Wert : Double ;
  Byte1, Byte2 :Byte;
  a : Double;
  write_add_temp : TArray = (1,0,0,1,0,0,0,0);
  read_add_temp : TArray = (1,0,0,1,0,0,0,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}


    
procedure TForm1.Button1Click(Sender: TObject);

 var
 val1 : TArray;
 val2 : TArray;
 temp1 : Byte;
 temp2 : Byte;
 Value : double ;
  i: ShortInt;
 begin

 ic := Ti2cUsb.Create;
 ic.Init(10);
 //Start
 ic.wr_byte_port(0);
 ic.wr_byte_port(2);
 //Send Adress Slave
 for i := 0 to 7 do
 begin
     if write_add_temp[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;

 //ACK
ic.wr_byte_port(3); //0 0
ic.wr_byte_port(2); //0 1
 // Write Init Register temp to 0
  for i := 0 to 7 do
 begin
     if init_temp[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;


 //ACK
 ic.wr_byte_port(3); //0 0
 ic.wr_byte_port(2); //0 1
 //Stop and Start again
 ic.wr_byte_port(3); //0 0
 ic.wr_byte_port(2); //0 1
 ic.wr_byte_port(0); //1 1
 ic.wr_byte_port(2); //0 1

  //Send Adress Slave
 for i := 0 to 7 do
 begin
     if read_add_temp[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;

   //ACK
 ic.wr_byte_port(3); //0 0
 ic.wr_byte_port(2); //0 1
 // 1. Byte read
 ic.rd_byte_port(temp1);

 //ACK
 ic.wr_byte_port(3); //0 0
 ic.wr_byte_port(2); //0 1

 // 2. Byte read
 ic.rd_byte_port(temp2);
 //ACK von Master
 ic.wr_byte_port(1); //1 0
 ic.wr_byte_port(0); //1 1

 //Stop condition
  ic.wr_byte_port(3); //0 0
 ic.wr_byte_port(2); //0 1
 ic.wr_byte_port(0); //1 1


 //Show Byte 1
 ShowMessage(temp1.ToString);
 ShowMessage(temp2.ToString);


  • Welcome to StackOverflow! Why are you talking about Async PRO? I don't see any reference in your code. Could you provide reference for i2cusb unit you use ? Which hardware interface are you using? Please edit your question to add more information. – fpiette Apr 11 '21 at 12:56
  • Not only are you lacking details, but the code you've dumped here is not even close to being compilable. Please provide a [mre] that demonstrates the issue. You'll find your experiences here will be much better if you spend some time taking the [tour] and reading the [help] pages to learn how the site works before you start posting. – Ken White Apr 11 '21 at 23:11

0 Answers0