Amiwerewolf
07.07.2006, 02:33
Hallo,
warum bekomm ich bei der I²C Hardware kein ACK zurück???? :-k
Benutze die M-Munit2.0 mit Basic++
Danke im vorraus, Michi
DECLARE FUNCTION i2cstart()
DECLARE FUNCTION i2cstop()
DECLARE FUNCTION i2cdevselect(adress AS BYTE)
DECLARE FUNCTION i2cbwrite(data AS BYTE)
DECLARE FUNCTION i2cgetack()
DEFINE SCL AS PORT [1]
DEFINE SDA AS PORT [2]
DEFINE temp AS BYTE
' Programmteil
Print "IIC Test Programm"
for temp = 1 to 255
Print "Scanning for I2C Device at " & temp
i2cstart()
pause 1
i2cdevselect(temp)
pause 1
i2cgetack()
i2cstop()
next temp
end
' Unterprogramme
SUB i2cstart()
SDA=1
SCL=1
pause 1
SDA=0
pause 1
SCL=0
END SUB
SUB i2cstop()
SDA=0
Pause 1
SCL=1
pause 1
SDA=1
END SUB
FUNCTION i2cdevselect(adress AS BYTE)
i2cbwrite(adress)
END FUNCTION
FUNCTION i2cgetack()
DEFINE i2c_ack_timeout AS WORD
SDA = 1
Deact SDA
i2c_ack_timeout=0
Do
i2c_ack_timeout=i2c_ack_timeout+1
'print i2c_ack_timeout & " | " & SDA
if SDA = 0 then Print "SDA EMPFANGEN"
Loop Until SDA = 0 Or i2c_ack_timeout = 5000
Pulse SCL
SDA = 1
END FUNCTION
FUNCTION i2cbwrite(data AS BYTE)
define i2c_data8 ref data at bit[1]
define i2c_data7 ref data at bit[2]
define i2c_data6 ref data at bit[3]
define i2c_data5 ref data at bit[4]
define i2c_data4 ref data at bit[5]
define i2c_data3 ref data at bit[6]
define i2c_data2 ref data at bit[7]
define i2c_data1 ref data at bit[8]
SDA=i2c_data1
'print SDA
pulse SCL
SDA=i2c_data2
'print SDA
pulse SCL
SDA=i2c_data3
'print SDA
pulse SCL
SDA=i2c_data4
'print SDA
pulse SCL
SDA=i2c_data5
'print SDA
pulse SCL
SDA=i2c_data6
'print SDA
pulse SCL
SDA=i2c_data7
'print SDA
pulse SCL
SDA=i2c_data8
'print SDA
pulse SCL
END FUNCTION
warum bekomm ich bei der I²C Hardware kein ACK zurück???? :-k
Benutze die M-Munit2.0 mit Basic++
Danke im vorraus, Michi
DECLARE FUNCTION i2cstart()
DECLARE FUNCTION i2cstop()
DECLARE FUNCTION i2cdevselect(adress AS BYTE)
DECLARE FUNCTION i2cbwrite(data AS BYTE)
DECLARE FUNCTION i2cgetack()
DEFINE SCL AS PORT [1]
DEFINE SDA AS PORT [2]
DEFINE temp AS BYTE
' Programmteil
Print "IIC Test Programm"
for temp = 1 to 255
Print "Scanning for I2C Device at " & temp
i2cstart()
pause 1
i2cdevselect(temp)
pause 1
i2cgetack()
i2cstop()
next temp
end
' Unterprogramme
SUB i2cstart()
SDA=1
SCL=1
pause 1
SDA=0
pause 1
SCL=0
END SUB
SUB i2cstop()
SDA=0
Pause 1
SCL=1
pause 1
SDA=1
END SUB
FUNCTION i2cdevselect(adress AS BYTE)
i2cbwrite(adress)
END FUNCTION
FUNCTION i2cgetack()
DEFINE i2c_ack_timeout AS WORD
SDA = 1
Deact SDA
i2c_ack_timeout=0
Do
i2c_ack_timeout=i2c_ack_timeout+1
'print i2c_ack_timeout & " | " & SDA
if SDA = 0 then Print "SDA EMPFANGEN"
Loop Until SDA = 0 Or i2c_ack_timeout = 5000
Pulse SCL
SDA = 1
END FUNCTION
FUNCTION i2cbwrite(data AS BYTE)
define i2c_data8 ref data at bit[1]
define i2c_data7 ref data at bit[2]
define i2c_data6 ref data at bit[3]
define i2c_data5 ref data at bit[4]
define i2c_data4 ref data at bit[5]
define i2c_data3 ref data at bit[6]
define i2c_data2 ref data at bit[7]
define i2c_data1 ref data at bit[8]
SDA=i2c_data1
'print SDA
pulse SCL
SDA=i2c_data2
'print SDA
pulse SCL
SDA=i2c_data3
'print SDA
pulse SCL
SDA=i2c_data4
'print SDA
pulse SCL
SDA=i2c_data5
'print SDA
pulse SCL
SDA=i2c_data6
'print SDA
pulse SCL
SDA=i2c_data7
'print SDA
pulse SCL
SDA=i2c_data8
'print SDA
pulse SCL
END FUNCTION