Successfully enable the fuse of CLKOUT, but can not program Nano anymore.

I try to enable the fuse of CLKOUT in Arduino Nano, so I setup ArduinoISP with an Uno with Arduino IDE and change the board.txt of low fuses of arduino nano from 0xFF to 0x3F (divided by 8 clock out from PB0), then program the new bootloader into the arduino nano. I saw the 2MHz clock out from PB0. (This part is correct.)

But I used to program the arduino nano with the following command in Windows

avrdude -c arduino -p atmega328p -C ../avrdude.conf -b 115200 -P COM6 -U flash:w:blink.hex

now it doesn't work. The error messages are

avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x12 avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x12 . . .

If I change the low fuses back to 0xFF, everything is working again (except no CLKOUT).

If programming through Arduino is not a good idea, I am willing to change to other methods (I am buying a USBasp programmer). But I am suspicious that the problem is something else. Suggestions are welcome.

You lowered the system clock rate, so I'm pretty sure you need to lower this to match: 115200

Thanks for the suggestion.

I think I tested 9600 too. But let me setup and retest again.

CrossRoads: You lowered the system clock rate, so I'm pretty sure you need to lower this to match: 115200

I reconstruct the setup and duplicate the problem. Then I try

avrdude -c arduino -p atmega328p -C ../avrdude.conf -b 9600 -P COM6 -U flash:w:blink.hex

the same problem.

I saw a puzzle in the process, maybe I should clarify this symptom first. After burn the new bootloader, I tried to upload a blink sketch from Arduino IDE, it seems to success. But now both Uno and Nano are both flash with the blink speed. However if I detached the Uno and power up the Nano alone, the Nano didn't blink. So it seems that the upload is not go to Nano? (If I leave the connect wire of Uno and Nano there, both boards will still blink with the earlier upload speed.)

I try to program the low fuse without divided clock by 8, then everything works good (great!). So the problem is indeed somehow related to the divided by 8 fuse bit.

I can work on the clock without divided by 8, but it will be nice to know how to fix the original problem. (Now I think about it, it indeed is confusing whether the system clock is now crystal's 16MHz, or 2MHz if the divided by 8 fuse is programmed.)

I try to enable the fuse of CLKOUT in Arduino Nano, so I setup ArduinoISP with an Uno with Arduino IDE and change the board.txt of low fuses of arduino nano from 0xFF to 0x3F (divided by 8 clock out from PB0), then program the new bootloader into the arduino nano. I saw the 2MHz clock out from PB0. (This part is correct.)

3F programs both the CLKOUT and the DIV8 fuses, so you need bootload and core adjusted for the new (2MHz) clock speed.

I'm pretty sure you need to lower this to match: 115200

Then I try avrdude -c arduino -p atmega328p -C ../avrdude.conf -b 9600 -P COM6 -U flash:w:blink.hex [and it doesn't work.]

The normal rate is 115200. If you divide the clock by 8, you need to use a bitrate of 115200/8, which is 14400; not 9600. (that's if you haven't used a special bootloader set up for a different clock/bitrate. The bootloader runs at a fixed bitrate proportional to the clockrate, without any sort of autobaud that would allow it to operate at other bitrates. The "-b 115200" has to exactly match the speed the bootloader and clock that is expected.

Thanks for information.

westfw: The normal rate is 115200. If you divide the clock by 8, you need to use a bitrate of 115200/8, which is 14400; not 9600.

That sounds very reasonable. But I try it few times with "-b 14400" and burn few times of bootloaders, it just doesn't work. Should be something still not set right.

Maybe with bare chip it will work, but this seems to be a problematical setting that I will avoid to work with Arduino boards.

You could also just program it with an ISP programmer and not use a bootloader? But timekeeping would be off by factor of 8 unless you use a board def with F_CPU=2MHz.

Or, if you just need a 2 MHz clock output you could run it at the full 16 like normal,and just reconfigure Timer1 or Timer2 to give you a 2 MHz clock output on one of it's PWM pins (and you lose PWM on another pin)

Timer2, TCCR2A=0x23, TCCR2B=0x01, OCR2A=0x07, OCR2B=0x04 (7 + 1 = 8 clock per cycle, no prescale (so 16MHz/8=2MHz), clear OC2B on match set at BOTTOM, compare match on OC2B (arduino pin 3, PD3) at 0x04 for 50% duty cycle. Takes out Pin 11 PWM too.

Timer1, TCCR1A=0x82, TCCR1B=0x19, OCR1A=0x04, ICR1=0x07 (as above, output on OC1A, swap OCR1B and change TCCR1A to 0x22 for output on OC1B) (1A, 1B are PB1, PB2, arduino pins 9 and 10, takes out PWM on the other pin too)

(off the top of my head. Pin has to be set output)

DrAzzy: You could also just program it with an ISP programmer and not use a bootloader? But timekeeping would be off by factor of 8 unless you use a board def with F_CPU=2MHz.

The problem seems to be on UART. I use Uno to program bootloader to Nano to output 2MHz clock, then I can upload blink sketch through Uno as ISP to Nano, that is no problem. The clock is now 8 times slower as I can tell from the blink speed. But I just can not upload program using COM port though my Nano board's CH340G.

I also play around F_CPU, but still can not make it right.

DrAzzy: Or, if you just need a 2 MHz clock output you could run it at the full 16 like normal,and just reconfigure Timer1 or Timer2 to give you a 2 MHz clock output on one of it's PWM pins (and you lose PWM on another pin)

This is what I did, so there is no reason I have to use the fuse approach to generate 2MHz clock. I came back to problem because I want to use full 16MHz clock on the CLKO pin by programming lower fuse to 0xBF. That part is working fully though.

I will close this issue now, thank you all for the valuable information.