Program works with Nano new bootloader but fails with old one

Hello,

I am facing a strange problem in a project running on a Nano board clone. The projet is built using avr-gcc compiler and avr-libc with a simple Makefile under Debian Buster GNU/Linux computer, I am not using the Arduino IDE. The circuit involves an Arduino Nano clone board, a BME280 pressure, temperature and humidity sensor connected at the I2C pins and a 2x16 char LCD display connected to the Nano using 4 data bit interface. I am using libraries from Github for LCD, I2C and BME280 device and avrdude to program the device. I only use the IDE for uploading the bootloader to the MCU. Tha program simply reads the sensor at 2500 ms intervals and display temperature, pressure and humidity on the LCD screen.

The problem is very strange and I am desperate cause I do not know where the problem is originated. The program works fine if I am using the new Nano bootloader, but if I upload the old bootloader with the IDE and upload the program with avrdude as usual with no errors, the LCD display does not show any characters. I do not know what is going on there.

So, I am not sure what are the bootloader diferences between old and new bootloader that can lead to my program to fail working. I have been reading the documentation and notice that main differences are bootloader size and something related to the watchdog that I think shoud not make any diferences in my case.

I can provide any kind of details you can require for trying to solve this problem. Is is not a real problem cause the program works OK with the new botloader but it is a matter of discovering what is going on here with the old one.

Thanks so much.
Ramiro.

Hi
Welcome to the community

Is your code use watchdog?

Hello, thanks for answering. As far as I know, I do not find any #include <avr/wdt.h> in the code.

Thanks.

Hello:

This is the program upload to the Arduino Nano with de old bootloader:

$ make prog
avrdude -p atmega328p -c arduino -b 57600 -P /dev/ttyUSB1 -U flash:w:meteo.hex:i

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
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 "meteo.hex"
avrdude: writing flash (8596 bytes):

Writing | ################################################## | 100% 2.54s

avrdude: 8596 bytes of flash written
avrdude: verifying flash memory against meteo.hex:
avrdude: load data flash data from input file meteo.hex:
avrdude: input file meteo.hex contains 8596 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.94s

avrdude: verifying ...
avrdude: 8596 bytes of flash verified

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done. Thank you.

An this is the program upload to the Arduino Nano using de new bootloader:

$ make prog
avrdude -p atmega328p -c arduino -b 115200 -P /dev/ttyUSB1 -U flash:w:meteo.hex:i

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f (probably m328p)
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 "meteo.hex"
avrdude: writing flash (8596 bytes):

Writing | ################################################## | 100% 1.42s

avrdude: 8596 bytes of flash written
avrdude: verifying flash memory against meteo.hex:
avrdude: load data flash data from input file meteo.hex:
avrdude: input file meteo.hex contains 8596 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 1.12s

avrdude: verifying ...
avrdude: 8596 bytes of flash verified

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done. Thank you.

ramiro@debian-nuc8i7:~/ARCHIVOS_IMPORTANTES/RADIOAFICION/MONTAJES/ARDUINO$ make prog

Everything seems to run smooth with no errors but program does not display anything on the LCD display when using the old bootloader.

Thanks.

Hello,

After several days of thinking and with the help of some friends, I finally discovered why my program failed using the old Nano bootloader and worked fine using the new Optiboot bootloader.

MCU PIN <----> PERIPHERAL PIN

SCL <----> BME280 SENSOR SCL
SDA <----> BME280 SENSOR SDA
PORTD0 (RXD) <----> LCD DATA 0
PORTD1 (TXD<----> LCD DATA 1
PORTD2<----> LCD DATA 3
PORTD3 <----> LCD DATA 4
PORTD4 <----> LCD RS
PORTD5 <----> LCD R/W
PORTD6 <----> LCD E

I found that old bootloader left UART active after booting, so that PORTD0 and PORTD1 did not work as intended output pins to control the LCD display. LCD library did not check for that neither I did it on my code.

I have been able to make my program work disabling UART at the beginning of my user code by writing a zero at 3 and 4 bits at the UCSR0B register:

int main(void)
{

UCSR0B &= 0xe7;

lcd_init(LCD_DISP_ON);

Now everything works as expected.

Regards.

1 Like

Good to know but, Why not just install the new bootloader?

Hello Hutkikz, thanks for answering, it is just a matter of knowing what
was going on here. I will return to the new bootloader but wanted to
know the reason of the strange behaviour with the old one.

Regards.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.