Go Down

Topic: Atmega328PB and USART1 (Read 417 times) previous topic - next topic

zdravke

Hi Folks,

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.

pert

hoping that this will work, but it didn't.
Please explain exactly what the problem is.

What else needs to be done in order to make USART1 default serial interface for MCU?
What you you mean by "default serial interface"?

Juraj

Do you use an Arduino package which supports the MCU?
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

zdravke

Yes, everything works fine with USART0. When I connect serial from CH340 to pins for USART1, there is no serial comms.

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.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

zdravke

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.

Juraj

#6
Nov 09, 2018, 11:43 am Last Edit: Nov 09, 2018, 11:44 am by Juraj
Yes, everything works fine with USART0. When I connect serial from CH340 to pins for USART1, there is no serial comms.
Do you use an Arduino package which supports the MCU?
Which one?
Did you flash the bootloader or is there one from factory?
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Budvar10

Quote
When I connect serial from CH340 to pins for USART1...
On-board CH340?
Maybe schematics could help.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

zdravke

Do you use an Arduino package which supports the MCU?
Which one?
I'm using Wattuino package. As I said, everything works with USART0.

https://github.com/watterott/Wattuino

pert

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:
https://github.com/MCUdude/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:
Code: [Select]
328.menu.clock.16MHz_external.upload.port=UART0
to:
Code: [Select]
328.menu.clock.16MHz_external.upload.port=UART1

If you want to stick with the wattuino hardware package then it will be more complex.

zdravke

#10
Nov 09, 2018, 04:10 pm Last Edit: Nov 09, 2018, 04:13 pm by zdravke
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:

https://github.com/MCUdude/MiniCore/blob/master/avr/bootloaders/optiboot_flash/atmega328pb/1000000L/optiboot_flash_atmega328pb_UART0_9600_1000000L.hex

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?
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

zdravke

#12
Nov 09, 2018, 05:08 pm Last Edit: Nov 09, 2018, 05:28 pm by zdravke
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.

westfw


Quote
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...


Quote
I tried this bootloader:
https://github.com/MCUdude/MiniCore/blob/master/avr/bootloaders/optiboot_flash/atmega328pb/1000000L/optiboot_flash_atmega328pb_UART0_9600_1000000L.hex
Do you intend to run at 1MHz?  And, that's a UART0 bootloader (see: it says "UART0" in the file name!)


Juraj

the common error is to choose Arduino ISP instead of Arduino as ISP
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Go Up