Failing to access AVR ATTiny13A with very slow clock (128kHz/128 or 128kHz/256) (avrdude: error: program enable: target doesn't answer) - avr

I am trying to program an AVR ATTiny13A using a USBasp adapter (guloprog) and avrdude. Uploading the program and running it works fine the first time for a fresh ATTiny13A device, but re-uploading again fails. avrdude cannot see/access the device at all. avrdude behaves like the device is not connected.
>avrdude -c usbasp -p t13 -B120 -U lfuse:r:-:b
avrdude: set SCK frequency to 8000 Hz
avrdude: error: program enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
If I reduce the communication speed to the minimum supported by avrdude
>avrdude -c usbasp -p t13 -B2000 -U lfuse:r:-:b
I get set SCK frequency to 500 Hz with the same result as above.
Looking at the programming signals with an oscilloscope, all signals look good, except for MISO which only shows rudiments of communication between 0V and 0.2V.
I have set the CKSEL fuses to 11, selecting the internal 128kHz clock source. In the program I set CLKPR to 8, dividing the 128kHz clock by 256, to get the slowest clock possible. (I have also set CKDIV8 to 1, but that should not matter.)
Have I fuse-bricked the IC? I do not have a HVSP to clear the fuses. What else can I do?

How to unbrick the AVR with a very slow clock divider setting
The problem is caused by writing CLKPR with a very slow clock divider setting (/128 or /256 with the 128kHz clock) in the program. After the program started, programming no longer works (regardless of the -B setting for avrdude).
Solution without HVSP (with pull-down resistor): Put a pull-down resistor between RESET and GND (10k worked for me). Now you can access the AVR again and program a different program, setting the clock divider to at most /64.
The pull-down resistor will keep the AVR in reset after power-up, not allowing the program to run, preventing the slow clock to be set. In order to run the new program you need to remove the pull-down resistor.
Alternative solution with HVSP
If you have a HVSP you can reset the CKSEL to 10 again to use the 9.6 MHz internal clock (and potentially set CKDIV8 to 0 again). This will allow you to access the device again.
Background
avrdude limits the slowest communication speed to a minimum of 500 Hz. This is hardcoded in the source, see https://github.com/avrdudes/avrdude/blob/5cbc9c37fc71c424e99bdcc00bb910fd581c2676/src/usbasp.c#L903
The device must be clocked at least four times faster than this speed. For 500 Hz communication speed this means that the AVR must run at 2000 Hz or higher. This means that the slowest clock-divider setting with the 128kHz clock which is compatible with avrdude is 128kHz/64 = 2000Hz (and this is already on the edge and may fail, but it worked well for me). To get the slowest avrdude communication speed (500 Hz) use the -B 2000 option, e.g.:
avrdude -c usbasp -p t13 -B2000 -U lfuse:r:-:b
which works:
avrdude: set SCK frequency to 500 Hz
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.15s
avrdude: Device signature = 0x1e9007 (probably t13)
avrdude: reading lfuse memory:
Reading | ################################################## | 100% 0.05s
avrdude: writing output file "<stdout>"
0b1101011
avrdude: safemode: Fuses OK (E:FF, H:FF, L:6B)
avrdude done. Thank you.
Uploading programs will be very slow, but for programs which are only a few instructions long this is feasible.

Related

How to get serial terminal software supporting high baudrate?

I'm working on communicating embedded device via serial port for debug. The device supports only 1843200 bps for baud rate.
But, my usual terminal softwares (minicom, Teraterm) don't look like supporting such high baud rate as they are.
What I want to do using such terminal software is:
sending command string interactively
transporting file to the device
Thank you.
As I commented, I solved the problem myself and post it again.
Teraterm ... high baudrate can be set from CUI (command line), not GUI (926100, max).
teratermpro.exe /BAUD=1843200 /C=1
PuTTy ... Using "plink.exe" works with options like below:
plink.exe -serial \.\COM1 -sercfg 1843200,8,n,1,N
But, you could have to stop "plink" once by Ctrl-c and type like below:
plink.exe -serial com1 -sercfg 1843200,8,n,1,N < [file path]
Regarding Linux, I didn't find the way. It could be that the proper driver should be installed.
#thebusybee Thank you for your kind advice!
What baudrate that is supported by a certain UART device depends on hardware:
How high the clock source for the UART clock go.
What prescalers/divisors the UART hardware support when translating the clock source to it's own hardware peripheral clock.
Some general rule of thumb is that divisors should not give more than 3% inaccuracy from the requested baudrate. More than that and you risk spurious data corruption, framing errors and similar.
Therefore software might limit the number of supported baudrates, not to correct higher ones that will be wildly inaccurate anyway.
Needless to say your embedded device also needs good clock accuracy, so if you are clocking it from something like an internal RC oscillator while running UART at 1.8MHz, you are very likely doing it wrong.
In ttermpro you can manually set the desired baudrate even if it does not show up in the drop-down list. Just type it into the field.

Arduino Programmer only works after unlugging and plugging back in

I'm using avrdude to program my Arduino. My Ardunio Uno is from China and the programmer reported in the device manager is ch340.
When I first connect the arduino to my computer, avrdude works one time. All subsequent times it fails unless I unplug it from the computer and plug it back in. I tried putting a 10uF capacitor from RST to GND, it didn't help. I also tried a different configuration:
programmer
id = "ch340";
desc = "ttl port banging, reset=!txd sck=!rts mosi=!dtr miso=!cts (invert signals using 74ls04)";
type = serbb;
reset = 3;
sck = 4;
mosi = 8;
miso = 7;
;
That also didn't help. With either of those solutions, I couldn't even get it to work the first time. Only with programmer "arduino" did I get it to work, but then only once.
Here is the output from the first run after connecting to USB:
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: safemode: Fuses OK
avrdude done. Thank you.
All runs after that:
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
avrdude done. Thank you.
I also tried the reset button the board, it didn't make a difference.
It appears to have been my version of avrdude. The one included with an avrgui that I downloaded is 5.6. The one on the arduino website is 6.0.1 and it works.

Unable to connect to Atmega328P chip with 16MHz crystal

I am trying to connect to Atmega328P chip through eXtreme Burner. I used 22pf capacitors and 10K pull for reset.
I am able to read the chip if I use 8 MHz Crystal. But cannot read if I connect 16MHz crystal. When I looked at the datasheet, it says fuse bits are same for 8 MHz and 16 MHz. I get "Power On Failed" error message with 16 MHz. I am using USBASP programmer.
Please note: With 8 MHz crystal, though I am able to read the device, I get error message "Incorrect Chip Found! Continue". If I press OK, it reads the data. The fuse bits read using 8 MHz crystal are: Low-- FF, High - DE, Extended -- FD, Lock Fuse - CF and Calibration - FFFFFFB1
What could be the issue?
Attached screen shots in the link
http://www.filedropper.com/extremeburnererrors
Its not in your settings then, so it must be in the setup of your hardware. Try different capacitor values. If I remember correctly, you have to vary the value of the capacitors as the frequency of your crystal varies. Also you have to take in to account the added inductance and capacitance of the breadboard or pcb and solder. So I would suggest just trial and error with different capacitor values.

new ATMEGA1281 and avrdude

I'm experiencing sometimes problems when programming my new ATMEGA1281. It is suposed to be the same as my old one, the only difference I guess is the serial number:
ATMEGA1281 16AU 1104 vs ATMEGA1281 16AU 1304
I'm used to program the ATMEGA1281 with avrdude command, but with the new chip, I have sometimes this error:
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0x0c != 0xff
avrdude: verification error; content mismatch
Do you know why I'm having this problem?
Thanks in advance!
What programmer do you use?
The brand new microcontroler might have lower clock than your previous one and it might be to slow for your programmer.
Try decreasing your programmer bitclock (-B option of avrdude). It should be 4 times slower than the clock. Then you can change microcontroller fuses and use the programmer with the old bitclock.

Writing to Micro SD from SHARC 21469 idle and speed issues.

I can properly read/write to a 2GB Kingston Micro SD using single pin SPI, but after writing using the WRITE_MULTIPLE_BLOCK command to write several blocks, the card goes into idle mode. I know this because when I try send a command to write more data, the card returns an 'in idle state' flag. I created a work around that pulls the card from idle after each write but this severely reduces the bandwidth. Does anyone know why this happens?
Also, the maximum SPI Baud I have obtained is 1Mbs. When I set the SPI clk to >1MHz the commands do not work properly. If I send commands at a baud of < 1Mbs then send the data at >1Mbs, the data is corrupted. Is there a reason I have not been able to get the 25MHz specification speed as listed in the SDCARD.org spec on p2?
https://www.sdcard.org/developers/tech/sdio/sdio_spec/Simplified_SDIO_Card_Spec.pdf
I got SPI Speeds less than 1 MBit/s when I tried to use the wrong SPI clock polarity once. Double check this, and this is also a possible candidate as a source for you "idle" error.

Resources