PDA

View Full Version : read/write eeprom



mel4853
- 27th February 2010, 20:42
First give credit to Peter Olsen who wrote these programs for a picaxe. I'm trying to convert using a 12F683 to write to a 24LC256 and read back from it. The Angel file downloads file to 24lc256 from PC. Newtoyshop is suppose to read from the 24lc256 and output to 2 74hc595's. When I write to eeprom then read back I get jumbled up mess. The Angel file runs in power basic.

mackrackit
- 27th February 2010, 21:33
In my opinion..
You would be better off not wasting time trying to convert a program that may or may not have worked for another platform.

You know what you want the program to do?
Write from scratch. In PBP...

mel4853
- 27th February 2010, 21:40
It did work on a picaxe. I'm trying to write it in PBP with the other program as a reference, being new at this having a heck of a time. Not giving up.

mackrackit
- 27th February 2010, 21:47
Not giving up is good!

To learn how to work with external eeproms try the I2C sample here
http://www.melabs.com/resources/samples.htm

Or wait till someone comes along that knows picaxe...

and this may help with the 595s.
http://www.picbasic.co.uk/forum/showthread.php?t=10200

Put something together in PBP and we will help you debug it.

aratti
- 27th February 2010, 21:56
Tray adding the following two defines:

DEFINE I2C_SLOW 1
DEFINE I2C_HOLD 1


Al.

mackrackit
- 27th February 2010, 22:07
DOH!!!

My apologies...
The way I read the first post I did not think you had any code of your own.

And I hate opening attachments...

Use code tags in the future.

mel4853
- 27th February 2010, 22:23
I'll try the Defines and whenever I use code tags the code jumbles up or leaves stuff out, tried this a couple times on other questions and it left parts of the code out.

Archangel
- 27th February 2010, 22:32
I'll try the Defines and whenever I use code tags the code jumbles up or leaves stuff out, tried this a couple times on other questions and it left parts of the code out.
replace the word magic with the word code

your code goes here

mel4853
- 27th February 2010, 23:50
The Defines worked!!! Couple other little changes and I believe it works, except for when I download from PC it just hangs. Cycle power and all takes off and works fine. Seems to get stuck in interrupt. Here's the code now trying Joe S. method.

Include "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
define osc 8
define DEBUGIN_REG GPIO
define DEBUGIN_BIT 3
define DEBUGIN_BAUD 2400
define DEBUGIN_MODE 1
define I2C_SLOW 1
define I2C_HOLD 1

Dpin var GPIO.2 'Data pin
Cpin var GPIO.0 'Clock pin
Lpin var GPIO.1 'Latch pin
Dapin var GPIO.4 '24LC256 data pin
Clpin var GPIO.5 '24lc256 clock pin
serialin var GPIO.3 'Input from PC
cont con $A0
addr var word
CMCON0=$07 'Shut off comparators
ANSEL=$00 'Set all digital
ADCON0=$00 'Shut off A/D Converter
TRISIO=$08 'Set all to outputs except GPIO.3 is input
INTCON.7=1 'Enable all unmasked interrupts
IOC=$08 'Enable interrupts on input3
GPIO=$00
b1 var byte
b2 var byte
chipnum var byte
thischip var byte


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler GPC_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE GPC_INT ; enable external (INT) interrupts
ENDASM

Start:
addr=0

loop:
I2Cread dapin,clpin,cont,addr,[b1,b2] 'Read from 24lc256
if b2=$FF then goto Start 'If b2=FF start over
for chipnum=0 to 1 'Load into 74hc595
lookup2 chipnum,[b2,b1],thischip 'Load into 74hc595
shiftout dpin,cpin,LSBFIRST,[thischip] 'Put out onto chips
next chipnum
pulsout lpin,10 'Latch data onto 74hc595
addr=addr+2 'Next eeprom location
pause 600
goto loop

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
addr=0 'Start writing at eeprom location 0
NEXTSTEP:
debugin[#b1,#b2] 'Read input
i2cwrite dapin,clpin,cont,addr,[b1,b2] 'Store in eeprom
pause 10 'Wait between writes
addr=addr+2 'Next eeprom loc
if b2 <> $FF then nextstep 'FF means end of data
low serialin
Finish:
@ INT_RETURN
end

mackrackit
- 28th February 2010, 00:12
Joe said to replace the word magic with the word code

mel4853
- 28th February 2010, 01:04
Sorry trying to fix supper for my daughter and was reading to fast.

Include "modedefs.bas"
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
define osc 8
define DEBUGIN_REG GPIO
define DEBUGIN_BIT 3
define DEBUGIN_BAUD 2400
define DEBUGIN_MODE 1
define I2C_SLOW 1
define I2C_HOLD 1

Dpin var GPIO.2 'Data pin
Cpin var GPIO.0 'Clock pin
Lpin var GPIO.1 'Latch pin
Dapin var GPIO.4 '24LC256 data pin
Clpin var GPIO.5 '24lc256 clock pin
serialin var GPIO.3 'Input from PC
cont con $A0
addr var word
CMCON0=$07 'Shut off comparators
ANSEL=$00 'Set all digital
ADCON0=$00 'Shut off A/D Converter
TRISIO=$08 'Set all to outputs except GPIO.3 is input
INTCON.7=1 'Enable all unmasked interrupts
IOC=$08 'Enable interrupts on input3
GPIO=$00
b1 var byte
b2 var byte
chipnum var byte
thischip var byte


ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler GPC_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE GPC_INT ; enable external (INT) interrupts
ENDASM

Start:
addr=0

loop:
I2Cread dapin,clpin,cont,addr,[b1,b2] 'Read from 24lc256
if b2=$FF then goto Start 'If b2=FF start over
for chipnum=0 to 1 'Load into 74hc595
lookup2 chipnum,[b2,b1],thischip 'Load into 74hc595
shiftout dpin,cpin,LSBFIRST,[thischip] 'Put out onto chips
next chipnum
pulsout lpin,10 'Latch data onto 74hc595
addr=addr+2 'Next eeprom location
pause 600
goto loop

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
addr=0 'Start writing at eeprom location 0
NEXTSTEP:
debugin[#b1,#b2] 'Read input
i2cwrite dapin,clpin,cont,addr,[b1,b2] 'Store in eeprom
pause 10 'Wait between writes
addr=addr+2 'Next eeprom loc
if b2 <> $FF then nextstep 'FF means end of data
low serialin
Finish:
@ INT_RETURN
end

Archangel
- 28th February 2010, 02:27
The Defines worked!!! Couple other little changes and I believe it works, except for when I download from PC it just hangs. Cycle power and all takes off and works fine. Seems to get stuck in interrupt.

I am thinking it is looping @ nexstep maybe it is not seeing $FF as there is no way out of the loop until it does = $FF

mel4853
- 28th February 2010, 02:56
At the end of PC download (Angel.bas) it puts out 255 on all

aratti
- 28th February 2010, 08:40
How many bytes you need to tx?

This piece of code is not working properly, since the delay due to the instructions to be executed plus the pause will surely make you loose Tx data.



NEXTSTEP:
debugin[#b1,#b2] 'Read input
i2cwrite dapin,clpin,cont,addr,[b1,b2] 'Store in eeprom
pause 10 'Wait between writes
addr=addr+2 'Next eeprom loc
if b2 <> $FF then nextstep 'FF means end of data



Think about to tx the whole packet in one go using array.

Replace pause 600 with For A0=1 to 120 :Pause 5:Next A0


Al.

mel4853
- 28th February 2010, 14:51
I'm sending a varible amount of bytes, so far have lost none. The pause 600 is up where I read from eeprom. There's a pause 10 in interrupt routine to give time to write to eeprom. Everything works but doesn't seem to want to exit interrupt routine.

aratti
- 28th February 2010, 15:41
Everything works but doesn't seem to want to exit interrupt routine.

Because you have a problem with the timing in serial TX/RX.(as mentioned in post#14)

Use a timeout to exit from DEBUGIN because you get stack there.

Al.

mel4853
- 28th February 2010, 17:37
Shouldn't it exit when b2=$FF? I send a $FF at the end of all the data I want sent.
if b2 <> $FF then nextstep 'FF means end of data
That's the way I understand, but I've been wrong alot of times.(As my wife says) If not I'll sure put in a timeout. Thanks.

mel4853
- 1st March 2010, 01:17
Put in the timeout and works perfectly. Thanks to all that helped.

Mike