Go Down

Topic: How to use 328PB as a Arduino uno? (Read 1 time) previous topic - next topic

Zumii_Z

How does that relate to your statement in the fist post;

I was actually responding to this;

Check the pinouts of the 328P vs 328PB again.
Thank you for the help. I am using UART to upload sketches to my project board. And no matter that 328p or 328pb they are both using the same pins for uploading sketches. I seriously checked their differences but that doesn't affect the failure i think.

kprims

Quote
I found from board.txt that the fuse bit should be DE FF F4 to enable external crystal to work.
When I changed the fuse bits, the microcontroller still doesn't work.
This is what I have after burning bootloader for m328pb 16Mhz using MiniCore.
 
Board is a clone Nano with m328pb chip and when loaded with the bootloader it was originally supplied with, identifies as a old Nano m328p using the Arduino IDE. Using avrdude it identifies as a m328pb.

 avrdude: Device signature = 0x1e9516 (probably m328pb)
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as F5

avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as F5
avrdude: safemode: Fuses OK (E:F5, H:D6, L:FF)

Loads sketches using Minicore with no problem.


westfw

#17
Oct 13, 2018, 03:37 am Last Edit: Oct 13, 2018, 03:38 am by westfw
Quote
A board built for a 328P will not be compatible with the pinout of the 328PB.
Actually, it will probably work.  Some of the pins that supplied power on the 328P are now IO pins, but as long as you don't enable them as outputs, that should be OK.


Quote
If you switched the fuses back to use internal clock with a failed crystal that would be a neat trick.
One of the improvements to the 328pb is "clock failure detection" - of the XOSC isn't working, it will switch over to the internal clock automatically.  (No more bricking boards by setting the fuses wrong!)

One of the dis-improvements is the removal of the full-swing crystal oscillator, and speccing the low-power oscillator at 16MHz "maximum."
https://hackaday.com/2016/05/03/atmel-removes-full-swing-crystal-oscillator/
https://www.avrfreaks.net/forum/atmega328pb-frequency-instability-issues-solved

This probably means that the oscillator is more sensitive to good layout and exact specifications of the crystal and associated components.  (I had some ATmega8 boards that needed "full swing" to run the 16MHz resonators that I had used.)

What could be happening is that your crystal isn't working, for one reason or another, causing the chip to revert to the internal oscillator.  Of course, that's a different frequency than your crystal, so the uart is not operating at the expected speed.

Zumii

Thank you WESTFW! I have changed my crystal for a test but it doesn't work. Can someone please be so kind as to post a schematic for reference? Also, what is the best parameter for fuse bits?

ron_sutherland

This is a board I did that has a 328pb,  it is working, but the MCU is at 3.3V and the crystal is 12MHz.

https://github.com/epccs/RPUadpt/tree/master/Hardware

The fuse bits I set are hear

https://github.com/epccs/RPUadpt/blob/master/Bootload/Makefile

Note: it does not have a bootloader, I just wanted a placeholder in case it made sense at some point. If you're not familiar with Makefiles, they are just a list of rules, that in this case run avrdude (and document how it was run as a side effect).
I use an R-Pi Zero on an RPUpi shield to have a tool-chain at the network edge.

Zumii

Thank you, Ron! I have looked into your schematic and Makefile. I believe you are SPI to download hex file without the bootloader to your chip. It makes sense to skip the FTDI download process with a tested program. But, I have to use the board for tests as well...

ron_sutherland

I have not put a serial bootloader on the 328pb yet, you did do that right? The IDE will set the fuses when it installs the bootloader, maybe it is time to have a look at the verbose output from when the IDE installs the bootloader.
I use an R-Pi Zero on an RPUpi shield to have a tool-chain at the network edge.

Zumii

Yes, and here it is about what has been outputed when I burn MiniCore Bootloader into the chip.

Code: [Select]
Using Port                    : usb
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part                      : ATmega328PB
         Chip Erase delay              : 9000 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        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9516 (probably m328pb)
avrdude: erasing chip
avrdude: Using SCK period of 10 usec
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

C:\Users\pcdalao\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/bin/avrdude -CC:\Users\pcdalao\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1/avrdude.conf -v -patmega328pb -cusbtiny -Uflash:w:C:\Users\pcdalao\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega328pb/optiboot_flash_atmega328pb_UART0_115200_16000000L.hex:i -Ulock:w:0x0f:m
Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3f:
avrdude: load data lock data from input file 0x3f:
avrdude: input file 0x3f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xfc"
avrdude: writing efuse (1 bytes):

Writing |  ***failed; 
################################################## | 100% 0.04s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xfc:
avrdude: load data efuse data from input file 0xfc:
avrdude: input file 0xfc contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: WARNING: invalid value for unused bits in fuse "efuse", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xf4 instead of 0xfc (double check with your datasheet first).
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xd6"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd6:
avrdude: load data hfuse data from input file 0xd6:
avrdude: input file 0xd6 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0b11111111"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0b11111111:
avrdude: load data lfuse data from input file 0b11111111:
avrdude: input file 0b11111111 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.

Zumii

Here is what happened when I try to upload the sketch.

Code: [Select]
D:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware D:\Program Files (x86)\Arduino\hardware -hardware C:\Users\pcdalao\AppData\Local\Arduino15\packages -hardware C:\Users\pcdalao\Documents\Arduino\hardware -tools D:\Program Files (x86)\Arduino\tools-builder -tools D:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\pcdalao\AppData\Local\Arduino15\packages -built-in-libraries D:\Program Files (x86)\Arduino\libraries -libraries C:\Users\pcdalao\Documents\Arduino\libraries -fqbn=MiniCore:avr:328:bootloader=true,variant=modelPB,BOD=4v3,LTO=Os,clock=16MHz_external -ide-version=10807 -build-path C:\Users\pcdalao\AppData\Local\Temp\arduino_build_245489 -warnings=none -build-cache C:\Users\pcdalao\AppData\Local\Temp\arduino_cache_365901 -prefs=build.warn_data_percentage=75 -verbose C:\Users\pcdalao\AppData\Local\Temp\untitled562483880.tmp\sketch_oct17a\sketch_oct17a.ino
D:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware D:\Program Files (x86)\Arduino\hardware -hardware C:\Users\pcdalao\AppData\Local\Arduino15\packages -hardware C:\Users\pcdalao\Documents\Arduino\hardware -tools D:\Program Files (x86)\Arduino\tools-builder -tools D:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\pcdalao\AppData\Local\Arduino15\packages -built-in-libraries D:\Program Files (x86)\Arduino\libraries -libraries C:\Users\pcdalao\Documents\Arduino\libraries -fqbn=MiniCore:avr:328:bootloader=true,variant=modelPB,BOD=4v3,LTO=Os,clock=16MHz_external -ide-version=10807 -build-path C:\Users\pcdalao\AppData\Local\Temp\arduino_build_245489 -warnings=none -build-cache C:\Users\pcdalao\AppData\Local\Temp\arduino_cache_365901 -prefs=build.warn_data_percentage=75 -verbose C:\Users\pcdalao\AppData\Local\Temp\untitled562483880.tmp\sketch_oct17a\sketch_oct17a.ino
Using board '328' from platform in folder: C:\Users\pcdalao\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1
Using core 'MCUdude_corefiles' from platform in folder: C:\Users\pcdalao\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1
Detecting libraries used...
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-IC:\\Users\\pcdalao\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.1\\cores\\MCUdude_corefiles" "-IC:\\Users\\pcdalao\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.1\\variants\\pb-variant" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\sketch\\sketch_oct17a.ino.cpp" -o nul
Generating function prototypes...
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-IC:\\Users\\pcdalao\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.1\\cores\\MCUdude_corefiles" "-IC:\\Users\\pcdalao\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.1\\variants\\pb-variant" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\sketch\\sketch_oct17a.ino.cpp" -o "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\preproc\\ctags_target_for_gcc_minus_e.cpp"
"D:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328pb -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_ATmega328 -DARDUINO_ARCH_AVR "-IC:\\Users\\pcdalao\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.1\\cores\\MCUdude_corefiles" "-IC:\\Users\\pcdalao\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.1\\variants\\pb-variant" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\sketch\\sketch_oct17a.ino.cpp" -o "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\sketch\\sketch_oct17a.ino.cpp.o"
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\pcdalao\AppData\Local\Temp\arduino_cache_365901\core\core_889ce42be26f135cdcebfde2f5aee103.a
Linking everything together...
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-gcc" -w -Os -Wl,--gc-sections -mmcu=atmega328pb -o "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/sketch_oct17a.ino.elf" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489\\sketch\\sketch_oct17a.ino.cpp.o" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/..\\arduino_cache_365901\\core\\core_889ce42be26f135cdcebfde2f5aee103.a" "-LC:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489" -lm
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/sketch_oct17a.ino.elf" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/sketch_oct17a.ino.eep"
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/sketch_oct17a.ino.elf" "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/sketch_oct17a.ino.hex"
"D:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\pcdalao\\AppData\\Local\\Temp\\arduino_build_245489/sketch_oct17a.ino.elf"
Sketch uses 578 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
C:\Users\pcdalao\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino14/bin/avrdude -CC:\Users\pcdalao\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1/avrdude.conf -v -V -patmega328pb -carduino -PCOM12 -b115200 -D -Uflash:w:C:\Users\pcdalao\AppData\Local\Temp\arduino_build_245489/sketch_oct17a.ino.hex:i

avrdude: Version 6.3-20171130
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\pcdalao\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1/avrdude.conf"

         Using Port                    : COM12
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xa5

ron_sutherland

Looks like something went wrong when it tried to set the fuses and then never install the bootloader. On Linux with avrdude 6.3, I tell it to add the signature to the configuration file to get it to work, but yours seems to recognize the signature (e.g. 0x1e 0x95 0x16).

I was using an Arduino Uno programmed with the example ISP sketch for my boards. You probably need to try some other ISP tools (I like them to have a dedicated USB to UART bridge,  like an Uno's 16u2).
I use an R-Pi Zero on an RPUpi shield to have a tool-chain at the network edge.

Zumii

Do you mean that the bootloader was not uploaded successfully because of the failure to set Efuse bit?
I don't understand how does that happen. I was using this USBTiny Isp the whole time and workes for all the other 328P/PA version.


Zumii

I try to write the bootloader directly to my chip with AVRDUDE and then read out what is on the chip. The two hex files are completely different, that probably could be the reason of failure.

How to fix that..?

Budvar10

How to fix? Just to write the bootloader again.
Post the file you've read out, just for sure.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

Zumii

That's the hex code should be like. optiboot_flash_atmega328pb_UART0_115200_16000000L
Code: [Select]
:107E000001C0ACC0112484B7882349F0982F9A7020
:107E1000923029F081FF02C097EF94BFD7D085E060
:107E20008093810082E08093C00088E18093C1004C
:107E300086E08093C20080E18093C4008EE0B1D0E0
:107E4000259A84E020E33CEF91E030938500209375
:107E5000840096BBB09BFECF1D9AA8958150A9F7D0
:107E6000C0E0D0E092D0813471F48FD0182F9FD031
:107E7000123811F482E005C0113811F486E001C017
:107E800083E07CD068C0823411F484E103C085347F
:107E900019F485E094D05FC0853541F476D0C82FC1
:107EA00074D0D0E0D82BCC0FDD1F54C0863521F420
:107EB00084E085D080E0E5CF843679F566D065D062
:107EC000D82E63D0F82E00E011E05FD0F801819346
:107ED0008F01DE12FACF6BD0F5E4FF1201C0FFCFA5
:107EE00040E050E063E0CE0139D07E0100E011E0D7
:107EF000F8014081818150E0582B61E0C7012ED00C
:107F0000F2E0EF0EF11C0E5F1F4FD012F1CF40E0F8
:107F100050E065E0CE0122D01EC0843771F435D028
:107F200034D0F82E32D043D08E01F80185918F01E4
:107F300025D0FA94F110F9CF0EC0853739F437D037
:107F40008EE11CD085E91AD086E19BCF813511F4F2
:107F500088E027D02CD080E111D084CFFC010A0129
:107F600067BFE895112407B600FCFDCF667029F0C5
:107F7000452B19F481E187BFE89508959091C000E1
:107F800095FFFCCF8093C60008958091C00087FFC5
:107F9000FCCF8091C00084FD01C0A8958091C600EF
:107FA0000895E0E6F0E098E1908380830895EDDFA6
:107FB000803219F088E0F5DFFFCF84E1DFCFCF9387
:107FC000C82FE3DFC150E9F7CF91F1CF282E80E031
:087FD000E8DFE0E0FF2709945F
:027FFE00020679
:0400000300007E007B
:00000001FF


This is the hex code that readed from it.
Code: [Select]
:207D6000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF23
:207D8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF03
:207DA000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE3
:207DC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC3
:207DE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA3
:207E000001C0ACC0112484B7882349F0982F9A70923029F081FF02C097EF94BFD7D085E00E
:207E20008093810082E08093C00088E18093C10086E08093C20080E18093C4008EE0B1D0DA
:207E4000259A84E020E33CEF91E0309385002093840096BBB09BFECF1D9AA8958150A9F713
:207E6000C0E0D0E092D0813471F48FD0182F9FD0123811F482E005C0113811F486E001C036
:207E800083E07CD068C0823411F484E103C0853419F485E094D05FC0853541F476D0C82F4E
:207EA00074D0D0E0D82BCC0FDD1F54C0863521F484E085D080E0E5CF843679F566D065D0B0
:207EC000D82E63D0F82E00E011E05FD0F80181938F01DE12FACF6BD0F5E4FF1201C0FFCF39
:207EE00040E050E063E0CE0139D07E0100E011E0F8014081818150E0582B61E0C7012ED051
:207F0000F2E0EF0EF11C0E5F1F4FD012F1CF40E050E065E0CE0122D01EC0843771F435D0AF
:207F200034D0F82E32D043D08E01F80185918F0125D0FA94F110F9CF0EC0853739F437D0CA
:207F40008EE11CD085E91AD086E19BCF813511F488E027D02CD080E111D084CFFC010A01EA
:207F600067BFE895112407B600FCFDCF667029F0452B19F481E187BFE89508959091C00095
:207F800095FFFCCF8093C60008958091C00087FFFCCF8091C00084FD01C0A8958091C600C3
:207FA0000895E0E6F0E098E1908380830895EDDF803219F088E0F5DFFFCF84E1DFCFCF935C
:207FC000C82FE3DFC150E9F7CF91F1CF282E80E0E8DFE0E0FF270994FFFFFFFFFFFFFFFFDF
:207FE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF020697
:00000001FF

Zumii


Go Up