I have bought Arduino Nano clones with Atmega328PB and all works fine apart one thing - I need to free PD0 and PD1 pins used by USART0, as they are the ones capable of playing as second 16-bit PWM output. I tried simply connecting CH340 to pins PB3 and PB4, which are TXD1 and RXD1 pins for USART1, hoping that this will work, but it didn't. What else needs to be done in order to make USART1 default serial interface for MCU? Datasheet is not clear to me.
sterretje:
Please give a proper description of the problem. No serial comms is too broad. During upload? At runtime?
I'm not familiar with the PB version, but others might be able to point you on the right direction.
During upload, so probably with everything else too, but cannot get to any other point at all. I'm guessing MCU has been setup to have USART0 ready for comms after boot, unlike USART1.
zdravke:
I'm guessing MCU has been setup to have USART0 ready for comms after boot, unlike USART1.
I think that's an incorrect assumption. It has nothing to do with the MCU. It's about the bootloader.
Probably the easiest way to switch to a bootloader that uses USART1 is to use MiniCore:
It comes with ATmega328PB bootloaders that are compiled for both serial ports. You only need to open its boards.txt file in a text editor, change the upload.port property to UART1, save the file, restart the Arduino IDE, burn the bootloader.
You need to make sure the upload.port property you change is the one associated with the Tools > Clock menu selection you're using in the Arduino IDE. For example, if you are using Tools > Clock > 16 MHz external then you would change the line:
328.menu.clock.16MHz_external.upload.port=UART0
to:
328.menu.clock.16MHz_external.upload.port=UART1
If you want to stick with the wattuino hardware package then it will be more complex.
Thanks. Unfortunately, burning bootloader from IDE never worked for me. I tried burning bootloader directly with avrdude (with Arduino as ISP), but I probably have incorrect settings. Flash went fine, but board does not react to upload requests from usb. I tried this bootloader:
I tried to make sure USART0 works fine before burning USART1 and switching wires, but it does not. Does anyone know what are the avrdude settings for burning this bootlader? I don't even know if this is the right bootloader...
Juraj:
What programmer do you use? Arduino as ISP?
Yes. Same programmer and all the connections work just fine with avrdude, never worked with IDE. I just do not know the settings for this specific bootloader.
Unfortunately, burning bootloader from IDE never worked for me. I tried burning bootloader directly with avrdude (with Arduino as ISP), but I probably have incorrect settings. Flash went fine, but board does not react to upload requests from usb.
Well, you should figure out how to get that working... If you want to bootload over USART1, you MUST replace the bootloader. You can't just dismiss it as "I can't get that working." There are many tutorials on burning bootloaders. Pick one, follow it, and let us know exactly where you have problems.
Preferably, figure out what's going on...
Ok, I took the command line from IDE after trying to burn bootloader and changed programmer type from -carduino to -cavrisp, and it went through. However, the bootloader does not seem to work -can't upload anything over USB. This is the original command line constructed by IDE:
zdravke:
Ok, I took the command line from IDE after trying to burn bootloader and changed programmer type from -carduino to -cavrisp, and it went through. However, the bootloader does not seem to work -can't upload anything over USB. This is the original command line constructed by IDE:
Ok, I don't get it. Avrdude flashes fine with switch "-c avrisp", but not with "-c arduino" (Arduino as ISP) which is the one IDE uses. My programmer is arduino nano with ArduinoISP sketch.
To use the -carduino switch, you need to put a 10 uF capacitor between the reset and ground pin on the programmer board to prevent it from resetting when the upload starts.
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\zdravke\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.0.1/avrdude.conf"
Using Port : COM4
Using Programmer : arduino
Overriding Baud Rate : 19200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x74
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x74