Bascom und SPI Eeprom

Jogi864

Neues Mitglied
29. Sep. 2014
15
0
1
Sprachen
  1. BascomAVR
Hallo zuammen,

Ich habe ein kleines Problem mit einem externen Eeprom.

Die Aufgabe: Ich will ein Array aus einem String mit 38 Bytes und dies 500 mal.
Da immer Fehler aufgetreten sind habe ich es auf 10 gekürzt.



CodeBox BascomAVR
$regfile = "m1284pdef.dat"
$crystal = 14745600
$hwstack = 128
$swstack = 256
$framesize = 256
$baud = 9600

Config Portb.4 = Output
Config Portb.7 = Output
Config Portb.5 = Output
Fram_cs Alias Portb.4 : Const Fram_csp = 4 : Const Fram_csport = Portb
Fram_so Alias Pinb.6 : Const Fram_sop = 6 : Const Fram_soport = Pinb
Fram_si Alias Portb.5 : Const Fram_sip = 5 : Const Fram_siport = Portb
Fram_sck Alias Portb.7 : Const Fram_sckp = 7 : Const Fram_sckport = Portb

$eepromsize = &H32000
$lib "fm25c256.lib"

Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 100 , Bytematch = 13
Open "com1:" For Binary As #1

Enable Interrupts

Dim Nc As Eram Word
Dim Eramdat(10) As Eram String * 38
Dim Dat2 As String * 38
Dim Dat As String * 3
Dim I As Word
Dim A As String * 3
Dim Anf As String * 4

Do
Wait 2

For I = 1 To 10
  Print #1 , I
  A = Str(i)
  Dat2 = A + "abcdefghijklmnopqrstuvwxyz" + A
  Eramdat(i) = Dat2
Next I

Wait 1

For I = 1 To 10
  A = Eramdat(i)
  Print #1 , A
Next I

Do

I = Val(anf)
If I <> 0 Then
  A = Eramdat(i)
  Print#1 , A
  Anf = "0"
  I = 0
End If

Loop

Loop

Serial0charmatch:
Input #1 , Anf , Noecho
Return



Zuerst habe ich mit einem 25LC256 von Microchip experimentiert. Laut Bascom Hilfe können diese eingestzt werden: Lib:FM25c256 Of course you can also use a cheaper normal SPI EEPROM. These are slower and have less write cycles.
Würde mir ja ausreichen. Aber es kam nur Müll beim Auslesen:

Code:
1
2
3
4
5
6
7
8
9
10
yz2
2abcdefghijklmnopqrstuvijklmnopqrstuvw
yz4
4abcdefghbcdefghij10
5abcdefghijklmnopqrstuvwxyz5
6abcdefghijklmnopqrstuvwxyz6
7abcdefghijklmnopqrsfghijklmnopqrstuvw
8abcdefghijklmnopqrstuvwxyz8
9abcdeefghij19
10abcdefghijklmnopqrstuvwxyz10

Nach langem herumsuchen fand ich auch den Fehler. In dem Datenblatt des Eeproms heißt es:
Page write operations are limited to writing bytes within a single physical page,
regardless of the number of bytes actually being written. Physical page boundaries
start at addresses that are integer multiples of the page buffer size (or ‘page size’)
and, end at addresses that are integer multiples of page size – 1. If a
Page Write command attempts to write across a physical page boundary, the
result is that the data wraps around to the beginning of the current page (overwriting
data previously stored there), instead of being written to the next page as might be
expected. It is therefore necessary for the application software to prevent page write
operations that would attempt to cross a page boundary.

Also wechsel zu Ramtron bzw Heute Cypress Eeprom FM25W256. Dann sieht das Ergebniss so aus:

Code:
1
2
3
4
5
6
7
8
9
10
41841841841841841841841
2abcdefghijklmnopqrstuvwxyz2
3abcdefghijklmnopqrstuvwxyz3
4abcdefghijklmnopqrstuvwxyz4
5abcdefghijklmnopqrstuvwxyz5
6abcdefghijklmnopqrstuvwxyz6
7abcdefghijklmnopqrstuvwxyz7
8abcdefghijklmnopqrstuvwxyz8
9abcdefghijklmnopqrstuvwxyz9
10abcdefghijklmnopqrstuvwxyz10

Immer das erste Feld des Arrays funktioniert nicht, egal ob das Array aus 10 oder 600 Einträgen besteht.
Liegt der Fehler in der fm25c256.lib oder übersehe ich was??

Danke für Eure Hilfe
Jogi
 
Hi, du übergibst in der 2. Schleife an 'A' das 'Eramdat', 'A' ist aber nur ein string mit 3 Stellen, 'Eramdat' hat 38 Stellen
 
Hallo Tschoeatsch,

Ja Du hast recht, das ist falsch. Vielen Dank. Hab das mal korrigiert und leider keine Änderung.
Nach langem Suchen habe ich jetzt den Fehler gefunden.
Während der Suche habe ich mir (mal wieder) ein kleines Testprogramm gemacht:


CodeBox BascomAVR
$regfile = "m1284pdef.dat"
$crystal = 14745600
$hwstack = 256
$swstack = 256
$framesize = 256
$baud = 9600

Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 20 , Bytematch = 13
'Config Serialout = Buffered , Size = 50

Open "com1:" For Binary As #1

Enable Interrupts

Dim Ramdat(50) As String * 3
Dim Dat2 As String * 3
Dim I As Word
Dim A As String * 3
Dim Anf As String * 3

For I = 1 To 50
  Print #1 , I
  A = Str(i)
  Dat2 = A
  Ramdat(i) = Dat2
Next I

Wait 1

Do

I = 0
I = Val(anf)
If I > 0 Then
  Print #1 , Anf
  Print#1 , I
  Dat2 = Ramdat(i)
  Print#1 , Dat2
  Anf = "0"
End If

Loop

Serial0charmatch:

Input #1 , Anf

Return


Dies hat gar nichts mit dem Eeprom zu tun.
Lässt man dieses Programm laufen, und gibt eine Zahl zwischen 1 und 50 ein sollte die gleiche Zahl vier mal im Terminalprogramm erscheinen. (Ich verwende HTERM)
Die erste Zahl ist das Echo welches die serielle empfangen hat.
Die zweite ist die Zeile "Print#1, Anf"
Die dritte ist die Zeile "Print#1, I"
Die vierte ist die Zeile "Print#1, Dat2"

Gibt man nun mehrere Male hintereinander Zahlen größer 10 ein , z.B. 12 kommt als Ergebnis mal 12 und manchmal 2 heraus.

Es hat eine Weile gedauert bis ich drauf gekommen bin:
In der Zeile Anf= "0" wollte ich den String löschen damit er mir nicht jedes mal in die Schleife läuft.
Offensichtlich ein grober Fehler, es muss heißen Anf = ""
Das dies solche Auswirkungen hat??

Und als letztes: $eepromsize = &H32000 ist falsch. Die Größe wird in Hex angegeben also $eepromsize = &H8000

Zum Schluss nochmal den funktionierenden Programmauszug:


CodeBox BascomAVR
$regfile = "m1284pdef.dat"
$crystal = 14745600
$hwstack = 256
$swstack = 256
$framesize = 256
$baud = 9600

Config Portb.4 = Output
Config Portb.7 = Output
Config Portb.5 = Output
Fram_cs Alias Portb.4 : Const Fram_csp = 4 : Const Fram_csport = Portb
Fram_so Alias Pinb.6 : Const Fram_sop = 6 : Const Fram_soport = Pinb
Fram_si Alias Portb.5 : Const Fram_sip = 5 : Const Fram_siport = Portb
Fram_sck Alias Portb.7 : Const Fram_sckp = 7 : Const Fram_sckport = Portb

$eepromsize = &H8000
$lib "fm25c256.lib"

Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 20 , Bytematch = 13
Config Serialout = Buffered , Size = 50

Open "com1:" For Binary As #1

Enable Interrupts

Dim Nc As Eram Word
Dim Eramdat(500) As Eram String * 38
Dim Dat2 As String * 38
Dim Dat As String * 3
Dim I As Word
Dim A As String * 3
Dim Anf As String * 3

For I = 1 To 500
  Print #1 , I
  A = Str(i)
  Dat2 = A + "abcdefghijklmnopqrstuvwxyzABCD" + A
  Eramdat(i) = Dat2
Next I

Wait 1

For I = 1 To 500
  Dat2 = Eramdat(i)
  Print #1 , Dat2
Next I

Do

I = 0
I = Val(anf)
If I > 0 Then
  Dat2 = Eramdat(i)
  Print#1 , Dat2
  Anf = ""
End If

Loop

Serial0charmatch:

Input #1 , Anf                               'Noecho

Return


Und Achtung: Die meisten der Fram Chips von Cypress vertragen nur 3,3 Volt. Ich verwende einen FM25W256-G der kann bis 5,5 Volt.

Jogi
 

Über uns

  • Makerconnect ist ein Forum, welches wir ausschließlich für einen Gedankenaustausch und als Diskussionsplattform für Interessierte bereitstellen, welche sich privat, durch das Studium oder beruflich mit Mikrocontroller- und Kleinstrechnersystemen beschäftigen wollen oder müssen ;-)
  • Dirk
  • Du bist noch kein Mitglied in unserer freundlichen Community? Werde Teil von uns und registriere dich in unserem Forum.
  •  Registriere dich

User Menu

 Kaffeezeit

  • Wir arbeiten hart daran sicherzustellen, dass unser Forum permanent online und schnell erreichbar ist, unsere Forensoftware auf dem aktuellsten Stand ist und der Server regelmäßig gewartet wird. Auch die Themen Datensicherheit und Datenschutz sind uns wichtig und hier sind wir auch ständig aktiv. Alles in allem, sorgen wir uns darum, dass alles Drumherum stimmt :-)

    Dir gefällt das Forum und unsere Arbeit und du möchtest uns unterstützen? Unterstütze uns durch deine Premium-Mitgliedschaft!
    Wir freuen uns auch über eine Spende für unsere Kaffeekasse :-)
    Vielen Dank! :ciao:


     Spende uns! (Paypal)