diff --git a/blk/160 b/blk/160 index f462242..002b509 100644 --- a/blk/160 +++ b/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) diff --git a/blk/163 b/blk/163 new file mode 100644 index 0000000..abb04cf --- /dev/null +++ b/blk/163 @@ -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 ; diff --git a/doc/avr.txt b/doc/avr.txt index c808ece..fcfb5f1 100644 --- a/doc/avr.txt +++ b/doc/avr.txt @@ -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 ) diff --git a/recipes/rc2014/avr.md b/recipes/rc2014/avr.md index d4d5945..d6d8823 100644 --- a/recipes/rc2014/avr.md +++ b/recipes/rc2014/avr.md @@ -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)