Tag: arduino

Arduino Nano with ATmega 328PB and Arduino IDE support

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
this check.
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:
https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json
Then go to Tools > Board > Board Manager and install MiniCore by MCUdude.

Now we can choose our board in tools:
Board: Atmega328
Bootloader: Yes
Clock: 16MHz external
BOD: 2.7v
Compiler LTO: Disabled (you can enable it if you need)
Variant: 328PB

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”
change
328.bootloader.unlock_bits=0x3f
to
328.bootloader.unlock_bits=0xff
Save & close the file.

You can use minicore for all 328p boards as well!

Done. Now we have fully functional 328PB with Arduino IDE.

USBASP V2.0 – warning: cannot set sck period

Cheap USBASP programmer which you china buy on ebay, ali and others. Official project WebPage: http://www.fischl.de/usbasp/

usbasp-v2.0-board-pinout

  • JP1 – Supply Target – Choose between 5V and 3.3V.
  • JP2 – Self Program – jumper on for self program, normally free
  • JP3 – Slow SCK – Jumper on only if the target clock is lower than 1.5 MHz.
  • LED R – Programmer communicating with target device
  • LED G – Power on
  • IDC pinout:
    usbasp-v2.0-idc-pinout

I will write how to solve:

avrdude: warning: cannot set sck period. please check for usbasp firmware update

You have to flash a new firmware version: usbasp.2011-05-28. Precompiled bin to flash is in \bin\firmware\ directory.

I’ve got USBASP with Atmega8 so I will use usbasp.atmega8.2011-05-28.hex and Arduino UNO R3 as ISP to flash it.

  1. First open ArduinoISP example in Arduino IDE 1.6.8 and upload the sketch (CTRL+U). Disconnect Arduino.
  2. Connect arduino to usb asp directly (without any adapter only cables) as follows:
    ArduinoUSBASP
    105 (RESET)
    111 (MOSI)
    129 (MISO)
    137 (SCK)
    5V2 (VCC +5V)
    GND10 (GROUND)
  3. Set jumper on JP2 (you can solder goldpins).
  4. Set power jumper for 5V (JP1)
  5. Connect only Arduino to USB and check which port com it use. You must not connect usbasp to usb!
  6. Download AVRDUDE avrdude-6.3-mingw32.zip: http://download.savannah.gnu.org/releases/avrdude/
  7. Copy correct hex file to avrdude.exe file directory.
  8. Check the connection with command:
    avrdude -c avrisp -P COMX -b 19200 -p ATmega8 -v

    avrdude: Version 6.3, compiled on Feb 17 2016 at 09:25:53
    Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    Copyright (c) 2007-2014 Joerg Wunsch

    System wide configuration file is “C:\WinAVR-20100110\bin\avrdude.conf”

    Using Port : COM4
    Using Programmer : avrisp
    Overriding Baud Rate : 19200
    AVR Part : ATmega8
    Chip Erase delay : 10000 us
    PAGEL : PD7
    BS2 : PC2
    RESET disposition : dedicated
    RETRY pulse : SCK
    serial program mode : yes
    parallel program mode : yes
    Timeout : 200
    StabDelay : 100
    CmdexeDelay : 25
    SyncLoops : 32
    ByteDelay : 0
    PollIndex : 3
    PollValue : 0x53
    Memory Detail :

    Block Poll Page Polled
    Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
    ———– —- —– —– —- —— —— —- —— —– —– ———
    eeprom 4 20 128 0 no 512 4 0 9000 9000 0xff 0xff
    flash 33 10 64 0 yes 8192 64 128 4500 4500 0xff 0x00
    lfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
    hfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
    lock 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
    calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00
    signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

    Programmer Type : STK500
    Description : Atmel AVR ISP
    Hardware Version: 2
    Firmware Version: 1.18
    Topcard : Unknown
    Vtarget : 0.0 V
    Varef : 0.0 V
    Oscillator : Off
    SCK period : 0.1 us

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.04s

    avrdude: Device signature = 0x1e9307 (probably m8)
    avrdude: safemode: hfuse reads as D9

    avrdude: safemode: hfuse reads as D9
    avrdude: safemode: Fuses OK (E:FF, H:D9, L:9F)

    avrdude done. Thank you.

    replace COMX with correct com port for arduino.

  9. Set the fuses like on Readme file:

    # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef
    # TARGET=atmega48 HFUSE=0xdd LFUSE=0xff
    # TARGET=atmega88 HFUSE=0xdd LFUSE=0xff

    with command:

    avrdude -c avrisp -P COM3 -b 19200 -p ATmega8 -v -e -u -U hfuse:w:0xC9:m -U lfuse:w:0xEF:m
  10. If it recognize the M8 you can flash it:
    avrdude -c avrisp -P COMx -b 19200 -p ATmega8 -v -U flash:w:usbasp.atmega8.2011-05-28.hex

    avrdude: Version 6.3, compiled on Feb 17 2016 at 09:25:53
    Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
    Copyright (c) 2007-2014 Joerg Wunsch

    System wide configuration file is “C:\WinAVR-20100110\bin\avrdude.conf”

    Using Port : COM4
    Using Programmer : avrisp
    Overriding Baud Rate : 19200
    AVR Part : ATmega8
    Chip Erase delay : 10000 us
    PAGEL : PD7
    BS2 : PC2
    RESET disposition : dedicated
    RETRY pulse : SCK
    serial program mode : yes
    parallel program mode : yes
    Timeout : 200
    StabDelay : 100
    CmdexeDelay : 25
    SyncLoops : 32
    ByteDelay : 0
    PollIndex : 3
    PollValue : 0x53
    Memory Detail :

    Block Poll Page Polled
    Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
    ———– —- —– —– —- —— —— —- —— —– —– ———
    eeprom 4 20 128 0 no 512 4 0 9000 9000 0xff 0xff
    flash 33 10 64 0 yes 8192 64 128 4500 4500 0xff 0x00
    lfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
    hfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
    lock 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
    calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00
    signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

    Programmer Type : STK500
    Description : Atmel AVR ISP
    Hardware Version: 2
    Firmware Version: 1.18
    Topcard : Unknown
    Vtarget : 0.0 V
    Varef : 0.0 V
    Oscillator : Off
    SCK period : 0.1 us

    avrdude: AVR device initialized and ready to accept instructions

    Reading | ################################################## | 100% 0.04s

    avrdude: Device signature = 0x1e9307 (probably m8)
    avrdude: safemode: hfuse reads as D9
    avrdude: NOTE: “flash” memory has been specified, an erase cycle will be performed
    To disable this feature, specify the -D option.
    avrdude: erasing chip
    avrdude: reading input file “usbasp.atmega8.2011-05-28.hex”
    avrdude: input file usbasp.atmega8.2011-05-28.hex auto detected as Intel Hex
    avrdude: writing flash (4700 bytes):

    Writing | ################################################## | 100% 7.34s

    avrdude: 4700 bytes of flash written
    avrdude: verifying flash memory against usbasp.atmega8.2011-05-28.hex:
    avrdude: load data flash data from input file usbasp.atmega8.2011-05-28.hex:
    avrdude: input file usbasp.atmega8.2011-05-28.hex auto detected as Intel Hex
    avrdude: input file usbasp.atmega8.2011-05-28.hex contains 4700 bytes
    avrdude: reading on-chip flash data:

    Reading | ################################################## | 100% 3.89s

    avrdude: verifying …
    avrdude: 4700 bytes of flash verified

    avrdude: safemode: hfuse reads as D9
    avrdude: safemode: Fuses OK (E:FF, H:D9, L:9F)

    avrdude done. Thank you.

  11. Done. Disconnect Arduino.

USBASP Drivers on Windows 8, 8.1 and Windows 10

Read this: http://tosiek.pl/manual-install-drivers-and-disable-drivers-signing-policy-on-windows-10-8-8-1/
You have to first disable check signed drivers on windows 8, 8.1 and 10!
(pull Shift and click to restart > Troubleshoot > Advanced options > Startup Settings > Restart button again > On the Startup Settings screen press 7 or F7 to disable driver signature enforcement.)
Download: usbasp-windriver.2011-05-28

Then install it manually in device manager.