I did not notice that i bought Arduino clone with ATmega328PB not with the ATmega328P, there is CH340C USB-UART chip. 328PB version is newer chip, some kind better than old.
Main disadvantage that chip is not supported by Arduino IDE and it came with unsupported bootloader to load sketches via Arduino IDE (even with added support to 328PB).
I tried to flash new bootloader via USBasp but i can’t change fuse bits. Fuses stays as it was!
avrdude: verification error, first mismatch at byte 0x0000
0x00 != 0xff
avrdude: verification error; content mismatch
Somehow i have disabled SPIEN (it enable serial programming and data downloading) and i could not program it via ICSP anymore. I got error but 328pb will be alive:
avrdude: auto set sck period (because given equals null)
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
avrdude done. Thank you.
Recover atmega 328 fuse bits
I have MiniPro Tl866 programmer that support atmega 328p programming. It not support 328PB, it has difference timings for programing but it works if you choose 328P.
But i could set fuse bits! You have to connect all pins like on scheme down below.
Then before you click program you have to connect XTAL1(PIN9) to pin 7 and XTAL2(PIN10) to pin 8 of 328PB (you have to touch it with small wires for 100ms of programming, do not need to solder).
Uncheck check ID. Set Config an click Programm with checked Config fuse bits and Lock bits:
Now we have to flash bootloader.
328pb Arduino IDE support and bootloader
We will use MiniCore that supports 328PB chip. On Arduino IDE 1.8.7 we can add support for this board in easy way. Open File > Preferences and add extra url for Board Manager:
Then go to Tools > Board > Board Manager and install MiniCore by MCUdude.
Now we can choose our board in tools:
Clock: 16MHz external
Compiler LTO: Disabled (you can enable it if you need)
Connect your programmer (i’m using usbasp) and choose Burn Bootloader.
Done, now you can write sketches via usb!
If something is still wrong you should set fuse by tl866 again or try this: For example open boards.txt from “C:\Users\user\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1”
Save & close the file.
You can use minicore for all 328p boards as well!
Done. Now we have fully functional 328PB with Arduino IDE.