mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-25 04:38:05 +11:00
avrpgm: add EEPROM support
also, verify all 3 first bytes of SPI commands. I'm not sure why I wasn't doing that, probably because I was getting a lot of AVR err and thought that only 2 bytes of the cmd were echoed. But now, with a reliable SPI setup, verifying 3 bytes seems to work.
This commit is contained in:
parent
8630b0a8ed
commit
eafcb0c440
4
blk/160
4
blk/160
@ -1,4 +1,4 @@
|
||||
( AVR Programmer, load range 160-162. doc/avr.txt )
|
||||
( AVR Programmer, load range 160-163. doc/avr.txt )
|
||||
( page size in words, 64 is default on atmega328P )
|
||||
CREATE aspfpgsz 64 ,
|
||||
VARIABLE aspprevx
|
||||
@ -6,7 +6,7 @@ VARIABLE aspprevx
|
||||
: _xc ( a -- b ) DUP (spix) ( a b )
|
||||
DUP aspprevx @ = NOT IF ABORT" AVR err" THEN ( a b )
|
||||
SWAP aspprevx ! ( b ) ;
|
||||
: _cmd ( b4 b3 b2 b1 -- r4 ) _xc DROP _x DROP _xc DROP _x ;
|
||||
: _cmd ( b4 b3 b2 b1 -- r4 ) _xc DROP _xc DROP _xc DROP _x ;
|
||||
: asprdy ( -- ) BEGIN 0 0 0 0xf0 _cmd 1 AND NOT UNTIL ;
|
||||
: asp$ ( spidevid -- )
|
||||
( RESET pulse ) DUP (spie) 0 (spie) (spie)
|
||||
|
6
blk/163
Normal file
6
blk/163
Normal file
@ -0,0 +1,6 @@
|
||||
: aspe@ ( addr -- byte, read from EEPROM )
|
||||
0 SWAP 256 /MOD ( 0 lsb msb ) SWAP
|
||||
0xa0 ( 0 msb lsb 0xa0 ) _cmd ;
|
||||
: aspe! ( byte addr --, write to EEPROM )
|
||||
256 /MOD ( b lsb msb ) SWAP
|
||||
0xc0 ( b msb lsb 0xc0 ) _cmd DROP asprdy ;
|
@ -103,3 +103,10 @@ aspfb! that divides dst addr by 2 because AMOVEW use byte-based
|
||||
addresses but aspfb! uses word-based ones. You also have to make
|
||||
sure that A@* points to @ (or another word-based fetcher)
|
||||
instead of its default value of C@.
|
||||
|
||||
# Access EEPROM
|
||||
|
||||
Accessing EEPROM is simple and is done byte-by-byte with words
|
||||
aspe@ and aspe!. Example:
|
||||
|
||||
0x42 0 aspe! 0 aspe@ .x ( prints 42 )
|
||||
|
@ -27,8 +27,8 @@ the "no division" position, and when I communicate with the
|
||||
AVR chip, I move the switch to increase the divisor.
|
||||
|
||||
Once you've done this, you can test that you can communicate
|
||||
with your AVR chip by doing `160 162 LOADR` (turn off your
|
||||
programmer or alse it might mess up the SPI bus and prevent you
|
||||
with your AVR chip by doing `160 163 LOADR` (turn off your
|
||||
programmer or else it might mess up the SPI bus and prevent you
|
||||
from using your SD card) and then running:
|
||||
|
||||
1 asp$ aspfl@ .x 0 (spie)
|
||||
|
Loading…
Reference in New Issue
Block a user