extended fuses BOD on Nano atmega328PB

I suspect I have BOD eeprom issues with my chinese Nano with ATMEGA328PB, so I wanted to set the BOD fuse to 4.3V. When I do repeated power cycles, I get corrupt content intermittently on random eeprom locations.

  1. How do I check to what it is fuse set to already?
  2. How do I reburn the bootloader on PB variant with ext fuses set to 0x04 (4.3V), as my 1.6.9 IDE Arduino as ISP programmer refuses to play ball with 328PB signature:

avrdude: Device signature = 0x1e9516
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

I tried optiloader and it burns bootloader just fine, boots and I can upload basic blink sketch, but when I upload my complex code, it just goes totally ballistic (garbage on display, rapid switching relays, etc).

I tried also with IDE 1.8.7, but Arduino ISP still does not work. I'm using another Arduino Nano as ISP programmer, and connections must be fine since Optiloader works.

Any ideas appreciated.

You can read out the fuses with ISP programmer like Arduino ISP is, and with the avrdude command from CMD. Switch -v will write fuses. See the help for avrdude. You will need to modify avrdude.conf to play with 328PB. Just copy and modify the section for 328P.
To change the fuse you need not to burn the bootloader because it is the same, to write a new fuse is enough.

Can’t see why setting BOD fuses will make any difference to the EEPROM content when you are power cycling as you say .BOD is intended just to reset the processor if the voltage dips, I assume you are powering it normally for these tests and not at marginal voltage?
What about your sketch , is that the culprit ?
You mention relays, these can cause power supply noise, depending on how they are wired.
As blink works , write a simple sketch to read the eeprom contents and see if that works .
There is a fuse setting for when eeprom is overwritten I believe.

Am I missing something ?

hammy:
Can’t see why setting BOD fuses will make any difference to the EEPROM content when you are power cycling as you say .BOD is intended just to reset the processor if the voltage dips, I assume you are powering it normally for these tests and not at marginal voltage?
What about your sketch , is that the culprit ?
You mention relays, these can cause power supply noise, depending on how they are wired.
As blink works , write a simple sketch to read the eeprom contents and see if that works .
There is a fuse setting for when eeprom is overwritten I believe.

Am I missing something ?

I have read somewhere that Atmega328P requires 3.8V at 16MHz to operate correctly. If voltage slides down slowly , sketch will perform eeprom write of few values between 4.6 and 4.3 V. After that, it will keep sliding down and enter brown out which is below 3.8V, continue until 2.7V and that's where all bets are off. The longer the brown out period, the higher the probability is that something will go south, and that's what I'm experiencing. I cannot deliver a project which works "most of the time".

I need everything to stop when voltage goes down to unsafe levels for 16MHz operation, which is below 3.8V. If it's stopping at 2.7V, that's too late.

http://jasper.sikken.nl/arduinobootloader/index.html

I managed to get fuse settings out with avrdude, but I'm not sure what they are set to:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x1e9516
avrdude: Expected signature for ATmega328P is 1E 95 0F
avrdude: safemode: lfuse reads as F7
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 7
avrdude: erasing chip

avrdude: safemode: lfuse reads as F7
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 7
avrdude: safemode: Fuses OK (H:07, E:DA, L:F7)

It seems that BOD is disabled altogether on these clones.

So I tried to write the efuse to 4 and it was successful. However, my bootloader is gone it seems, and I cannot find any bootloader that works for ATMEGA328PB. I tried several to no avail.

The bootloader has gone due to chip erase command which was not necessary. :wink:
Now you have to burn it again.

zdravke:
So I tried to write the efuse to 4 and it was successful. However, my bootloader is gone it seems, and I cannot find any bootloader that works for ATMEGA328PB. I tried several to no avail.

Are you not already using MiniCore, which has support for the 328PB? Out of curiousity, where did you get your 328PB Nano? I've been looking around for one for a while.

I got it from AliExpress by accident , didn’t even know pb existed.

I’d like to burn it again, but struggling to find a working bootloader. Last one I burned seemed to work, but code does not seem to be able to write to eeprom.

Did you mean to write to the EEPROM together with sketch?
Because if you do it form sketch, it has nothing with the bootloader.

zdravke:
I’d like to burn it again, but struggling to find a working bootloader. Last one I burned seemed to work, but code does not seem to be able to write to eeprom.

Since I assume you're using MiniCore (so that you can actually use the PB), you can just connect you programmer, select the right processor and speed, and hit Burn Bootloader. You shouldn't need to search for anything.

BJHenry:
Since I assume you're using MiniCore (so that you can actually use the PB), you can just connect you programmer, select the right processor and speed, and hit Burn Bootloader. You shouldn't need to search for anything.

I'm not using minicore, and I am wary of touching my IDE 1.6.9 in any way, since the latest versions break my IR code which is not using IR library due to timers interference, bla, bla. I'm stuck with avrdude for now.

I just copied command line and did not notice -e (erase) param in there. I was relying too much on other people's intelligence I guess. Now I have two nano's with messed up bootloaders.

Third one that is still working just browned out again during power cycle and got a corrupt eeprom. I did not have these problems at all with atmega328P boards, or maybe they all had BOD enabled at 4.3V - I don't know.

I disabled power down routine in sketch that was writing eeprom values during power off, and reduced time constant in power supply in order for voltage to go down faster. It seems that occurrences have been reduced, but they are still there.

I'm definitely going back to 328P boards, they were just working out of the mailbox.

I think I would write a simple sketch , not involving relays etc to confirm what you think is happening, is happening .
A BOD restart shouldn’t affect anything

It’s not the bod restart, it’s a manual power cycle that corrupts eeprom intermittently.

I managed to find a good bootloader and I restored both nanos with avrdude. I will now play with fuse settings to see how it goes.

Thanks everyone for the help.

Here's the PB version for those interested:

I just got another 5 boards from them and they are all PB variant.

Neat. It looks like without changing the wiring from a regular 328p, a 328pb would give you:

PWM on pin 3 (PD2). Also on PD1 and PD0, but those are normally the serial port.
Serial1 on pin11 and 12. (PB3,4) (and maybe USART in SPI mode on the traditional SPI pins?)
An extra 16bit timer or two (depending on whether you use the new PWM pins.)

westfw:
Serial1 on pin11 and 12. (PB3,4) (and maybe USART in SPI mode on the traditional SPI pins?)
An extra 16bit timer or two (depending on whether you use the new PWM pins.)

It works even, I have had a GPS using Serial1 and a SPI based LoRa device working on the second SPI interface.

Whilst it works, there can be problems with some libraries that check the processor type and look for 328P, they need changing to accept 328PB.

Oh! I forgot that a Nano breaks out A6 and A7 (now PE2 and PE3) as well; that does give you the second SPI port!