36
36
import busio
37
37
from digitalio import Direction , DigitalInOut
38
38
39
+ _SLOW_CLOCK = 100000
40
+ _FAST_CLOCK = 2000000
41
+
39
42
class AVRprog :
40
43
"""
41
44
Program your favorite AVR chips directly from CircuitPython with this
@@ -73,7 +76,7 @@ def verify_sig(self, chip, verbose=False):
73
76
Verify that the chip is connected properly, responds to commands,
74
77
and has the correct signature. Returns True/False based on success
75
78
"""
76
- self .begin ()
79
+ self .begin (clock = _SLOW_CLOCK )
77
80
sig = self .read_signature ()
78
81
self .end ()
79
82
if verbose :
@@ -179,7 +182,7 @@ def read_fuses(self, chip):
179
182
Each fuse is bitwise-&'s with the chip's fuse mask for simplicity
180
183
"""
181
184
mask = chip ['fuse_mask' ]
182
- self .begin ()
185
+ self .begin (clock = _SLOW_CLOCK )
183
186
low = self ._transaction ((0x50 , 0 , 0 , 0 ))[2 ] & mask [0 ]
184
187
high = self ._transaction ((0x58 , 0x08 , 0 , 0 ))[2 ] & mask [1 ]
185
188
ext = self ._transaction ((0x50 , 0x08 , 0 , 0 ))[2 ] & mask [2 ]
@@ -193,7 +196,7 @@ def write_fuses(self, chip, low=None, high=None, ext=None, lock=None):
193
196
Write any of the 4 fuses. If the kwarg low/high/ext/lock is not
194
197
passed in or is None, that fuse is skipped
195
198
"""
196
- self .begin ()
199
+ self .begin (clock = _SLOW_CLOCK )
197
200
lock and self ._transaction ((0xAC , 0xE0 , 0 , lock ))
198
201
low and self ._transaction ((0xAC , 0xA0 , 0 , low ))
199
202
high and self ._transaction ((0xAC , 0xA8 , 0 , high ))
@@ -221,14 +224,14 @@ def erase_chip(self):
221
224
"""
222
225
Fully erases the chip.
223
226
"""
224
- self .begin ()
227
+ self .begin (clock = _SLOW_CLOCK )
225
228
self ._transaction ((0xAC , 0x80 , 0 , 0 ))
226
229
self ._busy_wait ()
227
230
self .end ()
228
231
229
232
#################### Mid level
230
233
231
- def begin (self ):
234
+ def begin (self , clock = _FAST_CLOCK ):
232
235
"""
233
236
Begin programming mode: pull reset pin low, initialize SPI, and
234
237
send the initialization command to get the AVR's attention.
@@ -237,7 +240,7 @@ def begin(self):
237
240
if self ._spi :
238
241
while self ._spi and not self ._spi .try_lock ():
239
242
pass
240
- self ._spi .configure (baudrate = 1000000 )
243
+ self ._spi .configure (baudrate = clock )
241
244
self ._transaction ((0xAC , 0x53 , 0 , 0 ))
242
245
243
246
def end (self ):
0 commit comments