Hallo,
Ich habe einen I2C EEPROM 24FC1025
DB: http://ww1.microchip.com/downloads/en/DeviceDoc/21941B.pdf
an einen Atmega1284P angeschlossen.
Es wird die Hardware TWI genutzt, Pull-ups sind vorhanden.
Mein Problem ist nun, dass ich bisher nur lesen kann, aber nicht
schreiben.
Nein, am WP (Write protect Pin liegt es nicht).
Der Chip hat 2 pages, daher die etwas wuseligen Adressen.
Wenn ich lese, kommt immer 255 zurück, was ich von einem frischn EEPROM
auch erwarte. Spiele ich an den Adresspins, kommt 0 zurück. Das scheint
also OK zu sein.
Aber schreiben will einfach nicht.
Vielleicht entdeckt jemand gleich meinen Fehler und kann helfen?
Vermutlich habe ich einfach etwas übersehen, hier mal mein Bascom
Progrämmchen:
1 | $regfile = "m1284pdef.dat"
|
2 | $framesize = 32
|
3 | $swstack = 32
|
4 | $hwstack = 32
|
5 | $baud = 115200
|
6 | $crystal = 20e6
|
7 |
|
8 | Config 1wire = Portc.7
|
9 |
|
10 | $lib "i2c_twi.lbx"
|
11 | Config Scl = Portc.0 'Ports fuer IIC-Bus
|
12 | Config Sda = Portc.1
|
13 | Config Twi = 100000 ' Takt 100kHz
|
14 | I2cinit
|
15 |
|
16 | Dim T As Single
|
17 | Dim Dsid1 As Byte
|
18 | Dim Sc(9) As Byte
|
19 |
|
20 | Declare Function Ds18s20 As Single
|
21 |
|
22 | Declare Function R_ee(byval R_a As Integer) As Byte
|
23 |
|
24 | Declare Function W_ee(byval R_a As Integer , Bytetowrite As Byte) As Byte
|
25 |
|
26 |
|
27 |
|
28 | Dim Eeprom_r_0 As Byte
|
29 | Eeprom_r_0 = &B1010_0_00_1
|
30 |
|
31 | Dim Eeprom_w_0 As Byte
|
32 | Eeprom_w_0 = &B1010_0_00_0
|
33 |
|
34 | Dim Eeprom_r_1 As Byte
|
35 | Eeprom_r_1 = &B1010_1_00_1
|
36 |
|
37 | Dim Eeprom_w_1 As Byte
|
38 | Eeprom_w_1 = &B1010_1_00_0
|
39 |
|
40 | Dim Ead As Integer
|
41 |
|
42 | Dim X As Byte
|
43 | Dim S As String * 8
|
44 | Dim Ss As String * 8
|
45 |
|
46 | Dim Head As Byte
|
47 | Dim Lead As Byte
|
48 |
|
49 | Do
|
50 | Input "Case?" , X
|
51 |
|
52 | Select Case X
|
53 | Case 1
|
54 | Input "A2R?" , S
|
55 | Ead = Val(s)
|
56 | X = R_ee(ead)
|
57 | Print X
|
58 |
|
59 | Case 2
|
60 | Input "A2W?" , S
|
61 | Ead = Val(s)
|
62 | Input "B2W?" , Ss
|
63 | X = Val(ss)
|
64 | X = W_ee(ead , X)
|
65 | Waitms 50
|
66 | X = R_ee(ead)
|
67 | Print X
|
68 |
|
69 | Case 9
|
70 | T = Ds18s20()
|
71 | Print T
|
72 | End Select
|
73 | Loop
|
74 |
|
75 | End
|
76 |
|
77 |
|
78 | Function R_ee(byval R_a As Integer) As Byte
|
79 |
|
80 | Head = High(r_a )
|
81 | Lead = Low(r_a)
|
82 |
|
83 | I2cstart
|
84 | I2cwbyte &HA1
|
85 | I2cwbyte Head 'Head
|
86 | I2cwbyte Lead 'Lead
|
87 | I2crbyte R_ee , Nack
|
88 | I2cstop
|
89 | End Function
|
90 |
|
91 |
|
92 | Function W_ee(byval R_a As Integer , Bytetowrite As Byte) As Byte
|
93 | Head = High(r_a )
|
94 | Lead = Low(r_a)
|
95 |
|
96 | I2cstart
|
97 | I2cwbyte &HA0
|
98 | I2cwbyte Head 'Head
|
99 | I2cwbyte Lead 'Lead
|
100 | I2cwbyte Bytetowrite
|
101 | I2cstop 'Bytetowrite
|
102 |
|
103 | End Function
|
104 |
|
105 |
|
106 | Function Ds18s20
|
107 | 1wverify Dsid1
|
108 | 1wwrite &HBE
|
109 | Sc(1) = 1wread(9)
|
110 | Ds18s20 = Sc(1) * 0.5
|
111 | 1wreset
|
112 | 1wwrite &HCC
|
113 | 1wwrite &H44
|
114 | End Function
|