View previous topic :: View next topic |
Author |
Message |
Porelo
Joined: 23 May 2005 Posts: 39 Location: Portugal
|
Posted: Fri May 19, 2017 8:38 pm Post subject: Help me to understand what is wrong |
|
|
I want to write and read the data in an external eeprom 95640, but I'm having some problems. I need help to understand what's wrong the code is :
$regfile = "m128def.dat" ' specify the used micro
$crystal = 14745500 ' used crystal frequency
$baud = 38400 ' use baud rate
$hwstack = 100 ' default use 32 for the hardware stack
$swstack = 100 ' default use 10 for the SW stack
$framesize = 40
'DEFENIÇÃO DO LCD
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 6
'DEFENIÇÃO DO SPI
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1 , Spiin = 1
Enable Interrupts
Spiinit
Declare Function Read95640() As Word
Declare Function Write95640() As Word
' VARIAVEI GERAIS
' VARIAVEIS PARA 95640
95640_CS Alias PortE.5
Config 95640_CS = Output
Dim EndressoRead_Inicio as Word
Dim EndressoRead_Fim as Word
Dim Dados_na_Eeprom_Read(8) as Word
Dim EndressoWrite_Inicio as Word
Dim EndressoWrite_Fim as Word
Dim DadosWrite_Para_Eeprom(8) as Word
' ROTINA PARA VEREFICAÇÃO DE DADOS DA EEPROM ST95640
' Whole memory 0000h - 1FFFh = 8191 X8 =64K
' CHAMA ROTINA PARA VEREFICAR SE EXISTE UMA DATA DE INSTALAÇÃO
do
'EndressoWrite_Inicio = &H0000
'EndressoWrite_Fim = &h3
'DadosWrite_Para_Eeprom=4
'DadosWrite_Para_Eeprom=Write95640()
EndressoRead_Inicio = &H0000
EndressoRead_Fim = &h3
Dados_na_Eeprom_Read = Read95640()
loop
end
' ROTINA DA EEPROM
Function Read95640() As Word
'DEFENIÇÃO DA EEPROM
Local Eepromsize as word
Eepromsize = &H1FFF
Local Spi_read As Byte
local A As Byte
Local B As Byte
Spi_read = &B00000011 ' Read from Memory Array
Locate 1,1 :Lcd "Start Reading..."
While EndressoRead_Inicio < EndressoRead_Fim 'H0 to H3
A = High(EndressoRead_Inicio)
B = Low(EndressoRead_Inicio)
Reset 95640_CS 'Reset Portd.1
Spiout Spi_read , 1
Locate 2,1 : lcd Spi_read
Spiout A , 1
Spiout B , 1
Locate 3,1 : lcd A
Locate 4,1 : lcd B
Spiin Dados_na_Eeprom_Read(1) , 16
Locate 5,1 :Lcd Dados_na_Eeprom_Read
Incr EndressoRead_Inicio
locate 6,1 : lcd "Address: " ; EndressoRead_Inicio
locate 7,1 : lcd Dados_na_Eeprom_Read
Locate 8,1 :Lcd "Read Finished"
Set 95640_CS
Waitms 250
Wend
End Function
Function Write95640()' As Word
'DEFENIÇÃO DA EEPROM
Local Eepromsize as Word
Eepromsize = &H1FFF
Local I As Byte
Local Write_Enable As Byte
Local Write_to_Memory_Array As Byte
Local A As Byte
Local B As Byte
Write_Enable = &B00000110 ' Write Enable
Write_to_Memory_Array = &B00000010 ' Write to Memory Array
I=1
Locate 10,1 :Lcd "Start Write..." ; DadosWrite_Para_Eeprom
While EndressoWrite_Inicio < EndressoWrite_Fim 'H0 to H3
A = High(EndressoWrite_Inicio)
B = Low(EndressoWrite_Inicio)
Reset 95640_CS 'Reset Portd.1
Spiout Write_Enable , 1
nop
Locate 11,1 :Lcd Write_Enable
Spiout Write_to_Memory_Array , 1
nop
Locate 12,1 :Lcd Write_to_Memory_Array
Spiout A , 1
nop
Spiout B , 1
nop
Locate 13,1 :Lcd A
Locate 14,1 :Lcd B
Spiout DadosWrite_Para_Eeprom(1) , 4
nop
Locate 15,1 :Lcd Write_Enable;Write_to_Memory_Array;A;B;DadosWrite_Para_Eeprom
Incr I
EndressoWrite_Inicio=I
Locate 11,1 :Lcd "Write Finished"
Set 95640_CS
Waitms 100
Wend
End Function
Compiler 2.0.7.9.001
(BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Sat May 20, 2017 9:13 pm Post subject: |
|
|
And what is the problem?
Did you disabled the M103 compatible fuse? and the jtag fuse? _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
Porelo
Joined: 23 May 2005 Posts: 39 Location: Portugal
|
Posted: Sat May 20, 2017 11:34 pm Post subject: |
|
|
What I want is: to write data in the eeprom "st95640" in a certain address and later to read those data.
The fuses in ATMEGA128 compatible mode and the jtag disable.
I can read some data I previously recorded in eeprom on an external recorder, but I can not get the atmega128 to do this.
Thanks for the help.
I made some changes in the routine that was wrong but continued with the same problem.
$regfile = "m128def.dat" ' specify the used micro
$crystal = 14745500 ' used crystal frequency
$baud = 38400 ' use baud rate
$hwstack = 100 ' default use 32 for the hardware stack
$swstack = 100 ' default use 10 for the SW stack
$framesize = 40
'$sim
'DEFENIÇÃO DO LCD
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 2 , Cd = 3 , Wr = 0 , Rd = 1 , Reset = 4 , Fs = 5 , Mode = 6
'DEFENIÇÃO DO SPI
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = yes , Polarity = Low , Phase = 0 , Clockrate = 128 , Noss = 1 , Spiin = 1
Enable Interrupts
Spiinit
Declare Function Read95640() As Word
Declare Function Write95640() As Word
dim contador as Byte
contador =0
' VARIAVEI GERAIS
' VARIAVEIS PARA 95640
95640_CS Alias PortE.5
Config 95640_CS = Output
Dim EndressoRead_Inicio as Word
Dim EndressoRead_Fim as Word
Dim Dados_na_Eeprom_Read( as Word
Dim EndressoWrite_Inicio as Word
Dim EndressoWrite_Fim as Word
Dim DadosWrite_Para_Eeprom( as Word
SET portd.0 ' Back light
' ROTINA PARA VEREFICAÇÃO DE DADOS DA EEPROM ST95640
' Whole memory 0000h - 1FFFh = 8191 X8 =64K
' CHAMA ROTINA PARA VEREFICAR SE EXISTE UMA DATA DE INSTALAÇÃO
do
incr contador
EndressoWrite_Inicio = &H0000
EndressoWrite_Fim = &h3
DadosWrite_Para_Eeprom=4
DadosWrite_Para_Eeprom=Write95640()
EndressoRead_Inicio = &H0000
EndressoRead_Fim = &h3
Dados_na_Eeprom_Read = Read95640()
'if contador=3 then
' exit
'endif
loop Until contador=3
end
' ROTINA DA EEPROM
Function Read95640() As Word
'DEFENIÇÃO DA EEPROM
Local Eepromsize as word
Eepromsize = &H1FFF
Local Spi_read As Byte
local A As Byte
Local B As Byte
Spi_read = &B00000011 ' Read from Memory Array
Locate 1,1 :Lcd "Start Reading..."
While EndressoRead_Inicio < EndressoRead_Fim 'H0 to H3
A = High(EndressoRead_Inicio)
B = Low(EndressoRead_Inicio)
Reset 95640_CS 'Reset Portd.1
Spiout Spi_read , 1
Locate 2,1 : lcd Spi_read
Spiout A , 1
Spiout B , 1
Locate 3,1 : lcd A
Locate 4,1 : lcd B
Spiin Dados_na_Eeprom_Read(1) , 16
Locate 5,1 :Lcd Dados_na_Eeprom_Read
Incr EndressoRead_Inicio
locate 6,1 : lcd "Address: " ; EndressoRead_Inicio
locate 7,1 : lcd Dados_na_Eeprom_Read
Locate 8,1 :Lcd "Read Finished"
Set 95640_CS
Waitms 250
Wend
End Function
Function Write95640()' As Word
'DEFENIÇÃO DA EEPROM
Local Eepromsize as Word
Eepromsize = &H1FFF
Local Write_Enable As Byte
Local Write_to_Memory_Array As Byte
Local A As Byte
Local B As Byte
Write_Enable = &B00000110 ' Write Enable
Write_to_Memory_Array = &B00000010 ' Write to Memory Array
Locate 10,1 :Lcd "Start Write..." ; DadosWrite_Para_Eeprom
While EndressoWrite_Inicio < EndressoWrite_Fim 'H0 to H3
A = High(EndressoWrite_Inicio)
B = Low(EndressoWrite_Inicio)
Reset 95640_CS 'Reset Portd.1
Spiout Write_Enable , 1
nop
Locate 11,1 :Lcd Write_Enable
Spiout Write_to_Memory_Array , 1
nop
Locate 12,1 :Lcd Write_to_Memory_Array
Spiout A , 1
nop
Spiout B , 1
nop
Locate 13,1 :Lcd A
Locate 14,1 :Lcd B
Spiout DadosWrite_Para_Eeprom(1) , 4
nop
Locate 15,1 :Lcd Write_Enable;Write_to_Memory_Array;A;B;DadosWrite_Para_Eeprom
Incr EndressoWrite_Inicio
Locate 11,1 :Lcd "Write Finished"
Set 95640_CS
Waitms 300
Wend
End Function |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Sun May 21, 2017 5:09 am Post subject: |
|
|
Hello
You should read datasheet again with more attention
I read only 12 pages and find this. Im sure there is more nuances to find...
Quote: | For any instruction to be accepted, and executed,
Chip Select (S) must be driven High after the rising
edge of Serial Clock (C) for the last bit of the in-
struction, and before the next rising edge of Serial
Clock (C). |
|
|
Back to top |
|
|
Porelo
Joined: 23 May 2005 Posts: 39 Location: Portugal
|
Posted: Sun May 21, 2017 7:27 pm Post subject: |
|
|
Thanks EDC for the tip !
I read the datasheet, and I think everything is ok, but I still can not record the data, I read but I do not record, what is wrong? |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|