From eafcb0c44010895a3de4a11a20b2519cde4701b3 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 5 Oct 2020 19:32:42 -0400 Subject: [PATCH] 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. --- blk/160 | 4 ++-- blk/163 | 6 ++++++ doc/avr.txt | 7 +++++++ recipes/rc2014/avr.md | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 blk/163 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)