Selaa lähdekoodia

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.
master
Virgil Dupras 3 vuotta sitten
vanhempi
commit
eafcb0c440
4 muutettua tiedostoa jossa 17 lisäystä ja 4 poistoa
  1. +2
    -2
      blk/160
  2. +6
    -0
      blk/163
  3. +7
    -0
      doc/avr.txt
  4. +2
    -2
      recipes/rc2014/avr.md

+ 2
- 2
blk/160 Näytä tiedosto

@@ -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
- 0
blk/163 Näytä tiedosto

@@ -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 ;

+ 7
- 0
doc/avr.txt Näytä tiedosto

@@ -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 )

+ 2
- 2
recipes/rc2014/avr.md Näytä tiedosto

@@ -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…
Peruuta
Tallenna