如何解决从 LM75 I2C 读取温度
我正在尝试使用 LM75 和主站 (USB ITS) 在 i2c 总线中读取和写入字节。 使用来自 Github(AsyncPro for VCL 1.7)和 Delphi 的库。
我总是遇到的问题,当我编译到项目并尝试读取第一个字节和第二个 MSB LSB 时,我收到 253 或 255。请问有人可以帮我吗?谢谢 用于设置SCL和SDA的函数是带有参数的wr_byte_port()
- 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,1,0);
read_add_temp : TArray = (1,1);
write_add_pca : TArray = (0,0);
read_add_pca : TArray = (0,1);
init_temp : TArray = (0,0);
pointer_Byte : TArray = (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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。