Forum: Mikrocontroller und Digitale Elektronik AVR + I2C EEPROM


von Patrick (Gast)


Lesenswert?

Hallo AVR Gemeinde ;-),

ich habe folgendes Problem. Ich versuche mit einen ATMega32 Bytes in 
einen externen EEPROM zu schreiben. Später wollte ich das selbe dann mit 
Messwerten und Daten aus einer EEPROM Chipkarte tuen.

Schreiben funktioniert nach langen theoretischen Simulieren und 
Datenblatt studieren, aber das lesen und per UART ausgeben scheitert 
immer wieder.

Ich werd es morgen mal in "Wirklichkeit" probieren wenn ich wieder in 
meinen Bastelkeller bin aber bisher war der Simulator (Proteus) auch 
immer sehr hilfreich. Laut Logfile und EEPROM Inhalt war das speichern 
erfolgreich un es wurde auch der richtige Inhalt wieder 
zurückgeschickt...

Hier mal mein Code in Bascom
1
$regfile = "m32def.dat"                                     ' ATMega32
2
$crystal = 1000000                                          ' 1MHZ
3
$baud = 2400                                                ' Baudrate
4
5
$hwstack = 32                                               ' default use 32 for the hardware stack
6
7
$swstack = 10                                               ' default use 10 for the SW stack
8
9
$framesize = 16                                             ' default use 40 for the frame space
10
11
12
'=====
13
14
Config Scl = Portc.0                                        ' Porteinstellungen
15
Config Sda = Portc.1
16
Config I2cdelay = 10
17
18
Declare Sub Write_eeprom(byval Adres As Byte , Byval Adres2 As Byte , Byval Value As Byte)
19
Declare Sub Read_eeprom(byval Adres As Byte , Byval Adres2 As Byte , Value2 As Byte)
20
21
Print "Startprogramm"
22
Print
23
24
' 1010 E2 E1 E0 RW = 10100000 = 160
25
26
Const Addressw = 160                                        'EEPROM SCHREIB ADRESSE
27
Const Addressr = 161                                        'EEPROM LESE ADRESSE
28
29
30
Dim Value As Byte                                           'Datenbyte
31
Dim Value2 As Byte
32
Dim Adres As Byte                                           'Byte der Adresse
33
Dim Adres2 As Byte
34
Dim Outputt As String * 1
35
36
Dim A As Byte
37
38
39
40
                                            '1 Byte schreiben
41
Call Write_eeprom(1 , 0 , &B01010000 )                      'schreiben
42
Print "Geschrieben"
43
44
Call Read_eeprom(1 , 0 , Value2 )                           'schreiben
45
If Value2 = &B01010000 Then
46
Print "P"
47
Else
48
Print "F"
49
End If
50
51
52
53
End
54
55
'sample of writing a byte to EEPROM 24C02
56
Sub Write_eeprom(adres As Byte , Adres2 As Byte , Value As Byte)
57
    I2cstart                                                'Start
58
    I2cwbyte Addressw                                       'EEPROM Adresse Schreib
59
    I2cwbyte Adres                                          'Speicheradresse
60
    I2cwbyte Adres2                                         'Speicheradresse                                         'Speicheradresse
61
    I2cwbyte Value                                          'Inhalt
62
    I2cstop                                                 'Stop
63
    Waitms 10                                               'Warten
64
End Sub
65
66
67
Sub Read_eeprom(adres As Byte , Adres2 As Byte , Value2 As Byte)
68
    I2cstart                                                'Start
69
    I2cwbyte Addressw                                       'EEPROM Adresse Schreib
70
    I2cwbyte Adres                                          'Speicheradresse                                         'Speicheradresse
71
    I2cwbyte Adres2                                         'Speicheradresse
72
    I2cstart
73
    I2cwbyte Addressr                                       'EEPROM Adresse Les
74
    I2crbyte Value2 , Nack                                  'read byte
75
    I2cstop                                                 'Stop
76
    Waitms 10                                               'Warten
77
End Sub

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.