View previous topic :: View next topic |
Author |
Message |
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Sun Dec 21, 2014 10:07 pm Post subject: writing to eeprom variable |
|
|
Hi
Is it need to write "waitms 5" after writing to eeprom variable?
i see some code in web that use it for stable writing operation to eeprom, but i didnt see it in bascom help!
from bascom help:
"When data is written to the EEPROM, all interrupts are disabled, and after the EEPROM has been written, the interrupts are re-enabled."
is it mean that compiler produce this wait automatically for complete write operation to eeprom?
thanks
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Dec 22, 2014 1:01 pm Post subject: |
|
|
there is no specific delay like waitms 5 but a flag is checked when writing to the internal eeprom. the time varies depending on processor, voltage, speed, etc. So it is better to wait for the flag. the routines are in mcs.lib.
the 5 ms you mean is when writing to external eeprom (in case not flag is available or used). _________________ Mark |
|
Back to top |
|
|
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Mon Dec 22, 2014 2:59 pm Post subject: |
|
|
thank you albertsm
i check the time of writing to eeprom.
for this purpose i toggle a pin of microcontroller after writing to eeprom variable:
dim a as integer
dim ae as eram integer
do
ae=a
toggle portc.0
loop
end
from osciloscope i check portc.0 it take 14ms to complete writing to an integer that is 2 byte.
so i am sure that compiler produce its wait to complete writing to eeprom variable,and as seen in help bascom disable all interrupts in writing time.
i did not find the flag you say,if it is possible,i would like to know more about it.
thanks |
|
Back to top |
|
|
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Mon Dec 22, 2014 3:01 pm Post subject: |
|
|
thank you albertsm
i check the time of writing to eeprom.
for this purpose i toggle a pin of microcontroller after writing to eeprom variable:
dim a as integer
dim ae as eram integer
do
ae=a
toggle portc.0
loop
end
from osciloscope i check portc.0 it take 14ms to complete writing to an integer that is 2 byte.
so i am sure that compiler produce its wait to complete writing to eeprom variable,and as seen in help bascom disable all interrupts in writing time.
i did not find the flag you say,if it is possible,i would like to know more about it.
thanks |
|
Back to top |
|
|
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Mon Dec 22, 2014 3:05 pm Post subject: writing integer to at24c64 |
|
|
Hi
also i try to use external eeprom.
i try to split a integer variable to at24c64 but when i read the data its different from what i write!
my code is here:
Code: | $regfile = "m32def.dat"
$crystal = 4000000
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'-------------------------------------------------------------------------------
Config Sda = Portd.4
Config Scl = Portd.5
Config I2cdelay = 1
Const Eeread = 161
Const Eewrite = 160
'-------------------------------------------------------------------------------
Config Portd.7 = Output
Tester Alias Portd.7
'-------------------------------------------------------------------------------
Dim Address As Word , Highaddress As Byte , Lowaddress As Byte , Highintvar As Byte , Lowintvar As Byte
Dim Intvar As Integer
Dim J As Integer
Dim I As Integer
'-------------------------------------------------------------------------------
Config Portd.2 = Output
Intr Alias Portd.2
'-------------------------------------------------------------------------------
J = -30500
For I = 0 To 50
J = J + I
'Print #1 , J
Address = I
Highaddress = High(address)
Lowaddress = Low(address)
Highintvar = High(j)
Lowintvar = Low(j)
Print #1 , J
'Print #1 , I
'Print #1 , Highintvar
'Print #1 , Lowintvar
'Print #1 , "------"
Gosub Writeeepromserial
Toggle Tester
Next I
Print #1 , "read"
For I = 0 To 50
Address = I
Highaddress = High(address)
Lowaddress = Low(address)
Gosub Readeepromserial
'Print #1 , Highintvar
'Print #1 , Lowintvar
Intvar = Makeint(lowintvar , Highintvar)
Print #1 , Intvar
'Print #1 , "------"
Next I
End
'-------------------------------------------------------------------------------
Writeeepromserial:
I2cstart
I2cwbyte Eewrite
I2cwbyte Highaddress
I2cwbyte Lowaddress
I2crbyte Highintvar
I2crbyte Lowintvar
I2cstop
Waitms 5
Return
'-------------------------------------------------------------------------------
Readeepromserial:
I2cstart
I2cwbyte Eewrite
I2cwbyte Highaddress
I2cwbyte Lowaddress
I2cstart
I2cwbyte Eeread
I2crbyte Highintvar , Nack
I2cstop
Waitms 5
I2cstart
I2cwbyte Eewrite
I2cwbyte Highaddress
I2cwbyte Lowaddress
I2cstart
I2cwbyte Eeread
I2crbyte Lowintvar , Nack
I2cstop
Waitms 5
Return
'------------------------------------------------------------------------------- |
what is the problem? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Dec 25, 2014 10:00 pm Post subject: |
|
|
the flag is in the EECR register. Bit EEPE. You need to read the data sheet for this kind of info.
This is some code from the lib :
_CheckEpromReady:
* Sbic EECR,1 ; skip next instruction if ready
Rjmp _CheckEpromReady ; not ready for write
As mentioned, time depends on number of bytes you write, and the internal timing of the chip. There is NO waitms in the lib! It is a self timed operation.
The datasheet contains the timing parameters too. atomic erase and write takes 3.4 ms for a cell/byte in a tiny1634. _________________ Mark |
|
Back to top |
|
|
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Fri Dec 26, 2014 1:03 pm Post subject: |
|
|
Thank you Albertsm
another question:
i have 2 interrupt in my code that should never lost!
when my code goto interrupt rotine, i save my critical variable(an integer variable) to eeprom.but this take a time of 14ms as i measure(you say it take 3.5ms for each cell ,it mean a integer should take 7 ms!!),so the speed of running my other code is very low,because most of time my code is in interrupt code and wait for eeprom to complete writing integer variable.
i want to write in eeprom,and then return from my interrupt immediately.
i know that minimum time between 2 interrupt is 15ms, so it is enough time to complete writing an integer variable to eeprom.
after goning to interrupt again, i check the status of EECR register. Bit EEPE, and if ok i write new value into eeprom.
this way,i can execute other code while writing to eeprom completing!
but now my code wait by compiler to complete writing to eeprom, and then return from interrupt!
what should i do?
thanks |
|
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
|
|