Arduino Forum

Using Arduino => Microcontrollers => Topic started by: jopiek on Aug 25, 2015, 09:41 pm

Title: ATmega328PB with Arduino
Post by: jopiek on Aug 25, 2015, 09:41 pm
I can't seem to find the term ATmega328PB anywhere here, but are there people who have used the ATmega328PB and programmed it using the Arduino IDE / toolkit?

The ATmega328PB has in interesting feature that I am interested in: a second twi port. Other chips also offer that but I like the fact that it is basically an ATmega328 chip so I know the chip quite well already.
Title: Re: ATmega328PB with Arduino
Post by: DrAzzy on Aug 25, 2015, 11:19 pm
Is it actually available?
Title: Re: ATmega328PB with Arduino
Post by: jopiek on Aug 25, 2015, 11:55 pm
Well at least I ordered some samples from Atmel and there is a prototyping version with Arduino shield pin compatibility available!
Title: Re: ATmega328PB with Arduino
Post by: DrAzzy on Aug 26, 2015, 06:16 am
Nice!

Uh... what was that about a second TWI? It looks like it just has the one...
Title: Re: ATmega328PB with Arduino
Post by: jopiek on Aug 26, 2015, 08:12 am
http://www.atmel.com/devices/ATMEGA328PB.aspx?tab=parameters

SPI:2
TWI(I2C): 2
UART: 2
...
Title: Re: ATmega328PB with Arduino
Post by: DrAzzy on Aug 26, 2015, 04:54 pm
Yet the datasheet says... nothing about a second UART, SPI, or TWI interface....
Title: Re: ATmega328PB with Arduino
Post by: dmjlambert on Aug 26, 2015, 05:13 pm
This one does, I was just browsing it and looking at that info.
http://www.atmel.com/Images/Atmel-42397-8-bit-AVR-Microcontroller-ATmega328PB_Datasheet.pdf (http://www.atmel.com/Images/Atmel-42397-8-bit-AVR-Microcontroller-ATmega328PB_Datasheet.pdf)
Title: Re: ATmega328PB with Arduino
Post by: DrAzzy on Aug 26, 2015, 09:09 pm
Hmm, okay - yeah, some parts of the datasheet list it, others don't...

The pin diagram doesn't, the chart does, the SPI description mentions two SPI's, but the TWI and serial sections don't, and the register descriptions don't list the register names.
Title: Re: ATmega328PB with Arduino
Post by: westfw on Aug 26, 2015, 09:30 pm
Quote
the datasheet says... nothing about a second UART, SPI, or TWI interface.
It mentions them in the "features" section, in table 6-1 "Port Function Multiplexing", and section 15.11 "Power Reduction Register", but not in the individual TWI/USART sections, and the control registers do not appear in the "register summary"...   There is no "iom328pb.h" file in the latest Atmel Toolchain that defines anything specific to the PB chip, and it does not appear as a selectable device in the current version of Atmel Studio.
The ATmega168PB, announced at a similar time (Nov, 2014) but more available, does not list extra serial controllers.

Disappointing.

None of the usual distributers have the chips (although several have the Xplained mini eval board.)  This is more typical of Atmel; being very slow to ship announced parts.  Usually their documentation is in better shape during the "I want that and I can't get it yet" phase.  :-(

Title: Re: ATmega328PB with Arduino
Post by: westfw on Aug 27, 2015, 10:27 am
Aha.   There is:
 (http://www.atmel.com/tools/atmelstudio.aspx?tab=overview)
Quote
http://www.atmel.com/tools/atmelstudio.aspx?tab=overview (http://www.atmel.com/tools/atmelstudio.aspx?tab=overview)
...
ATmega328PB Part Pack for Atmel Studio 6.2
 (37.9 MB, updated July 2015)
 This bundle adds support for ATmega328PB device in Atmel Studio 6.2.SP2. Please see attached word file for more details.
Which installs an iom328pb.h, which contains:
Code: [Select]
#define UCSR1A _SFR_MEM8(0xC8)
 :
#define TWBR1   _SFR_MEM8(0xD8)

And related code defining the second UART and TWI interface, and etc.  So I guess they're real.
(A bit messy.  TWBR0 and TWBR1 used to be bits in the TWBR register (which was stupid, anyway.)   Now they're the bitrate registers for the two TWI peripherals...)  (similarly for the other TWI registers, I guess.)  (This probably means that adding support for the 2nd TWI interface is not going to be very easy; the existing code all assumes a single TWI interface with fixed TWBR/TWSR/etc registers.)

Title: Re: ATmega328PB with Arduino
Post by: jopiek on Aug 27, 2015, 02:28 pm
In http://www.atmel.com/Images/Atmel-42397-8-bit-AVR-Microcontroller-ATmega328PB_Datasheet.pdf the 6. I/O Multiplexing shows:

TW0-SDA on pin 27
TW0-SCL on pin 28
TW1-SDA on pin 3
TW1-SCL on pin 6

So I don't understand DrAzzy why you can't find it, it is just a matter of reading it carefully isn't it?! That those are not listed in the initial pin mappings is understandable since they are already showing too many features per pin.

@westfw: thanks for the insight. I ordered some of those evaluation boards, so will try it when I have them. I think this chip will be great for a lot of applications that require to make modular units in one's system (like my applications do).
Title: Re: ATmega328PB with Arduino
Post by: DrAzzy on Aug 27, 2015, 06:15 pm
So I don't understand DrAzzy why you can't find it, it is just a matter of reading it carefully isn't it?!
Yes, I'm sorry that I missed that. I guess I just didn't read carefully enough. I can find it now, obviously.
Title: Re: ATmega328PB with Arduino
Post by: westfw on Sep 22, 2015, 07:44 am
There's a new datasheet out that seems to include the "missing" definitions in the register summary:
http://www.atmel.com/Images/Atmel-42397-8-bit-AVR-Microcontroller-ATmega328PB_Datasheet.pdf (http://www.atmel.com/Images/Atmel-42397-8-bit-AVR-Microcontroller-ATmega328PB_Datasheet.pdf)
Title: Re: ATmega328PB with Arduino
Post by: retrolefty on Sep 22, 2015, 10:14 am
Pluses: More serial/TWI ports, more timer ports.

Minus: 
On first review of this new 'B' version, seems to not be available in DIP layout? That kind of sucks for some of us hobbyist types.

Title: Re: ATmega328PB with Arduino
Post by: westfw on Sep 22, 2015, 10:24 am
Quote
seems to not be available in DIP layout?
That appears to be the case :-(
(It would have been SO nice to drop a DIP into an existing Uno/etc and get that extra serial port!)
Title: Re: ATmega328PB with Arduino
Post by: jopiek on Sep 22, 2015, 05:44 pm
Great that they updated the datasheet! You could also rework an SMD one of course.
Title: Re: ATmega328PB with Arduino
Post by: crackn on Sep 26, 2015, 08:47 pm
Great that they updated the datasheet! You could also rework an SMD one of course.
Hello, we are trying to do it with an arduino UNO smd. we replaced the mcu with the PB one but it need a lot of changes in software. new chip ID, avrdude needs to be patched, bootloader not working, the arduino files need to be updated to support the new PB registers. there's a lot of work to do.

cheers,

crackn
Title: Re: ATmega328PB with Arduino
Post by: dmjlambert on Sep 27, 2015, 05:57 am
trying to do it with an arduino UNO smd. we replaced the mcu with the PB one
I suppose you would have to avoid soldering down MCU pins 3 and 6 so you can use those for input/output.   Did you bend up those legs and solder wires to them directly or something like that?  And since pins 19 and 22 aren't used on the Uno did you do the same thing with those pins?
 
Where do you order the PB?

Title: Re: ATmega328PB with Arduino
Post by: crackn on Sep 27, 2015, 09:39 am
Hi, you dont need to avoid those pins, since i will not use them (3/6 are 2nd i2c and 19/22 are 2nd SPI). the problems are that arduino ide dont know that uno PB has 2 uarts and 5 timers, 2 SPI, 2 i2c... the arvdude need to be configured by hand to support the new chip ID.. even atmel studio needs a patch to work with 328PB.

I received some Engineering samples from a friend that works at Atmel.

cheers,
cRACKn
Title: Re: ATmega328PB with Arduino
Post by: westfw on Sep 29, 2015, 09:53 am
Quote
it need a lot of changes in software. new chip ID, avrdude needs to be patched, bootloader not working, the arduino files need to be updated to support the new PB registers.
the big problem at the moment is that the compiler doesn't support the 328pb. You need a "snapshot" from Atmel just to support it under Atmel Studio, and the arduino compiler doesn't have those changes yet.

It should be "easy" to use the 328pb AS a 328p.  It should be a lot like using a 328 (non-p) - load up a lying copy of optiboot (ie the standard 328p version), and tell everything else that you have a 328p.  (of course, this doesn't give you access to the new features, which would be "nice.")   I didn't have to make any changes to optiboot to get it working on an Atmel Xplained Mini 328pb eval board, other than setting the speed to 57600 because the mEDBG chip doesn't seem to work at 115200bps.  (although you need mEDBG 1.6+ firmware to get auto-reset, and putting optiboot onto the 328pb currently requires Atmel Studio or some other heroics.)

Title: Re: ATmega328PB with Arduino
Post by: dmjlambert on Sep 30, 2015, 12:22 am
I suppose it would be pretty easy to smoke the 328PB if MCU pins 3 and 6 are connected to GND and VCC as in a typical 328P layout and in a sketch you set those data lines as outputs.
Title: Re: ATmega328PB with Arduino
Post by: PaoloP on Feb 26, 2016, 09:33 am
--> https://github.com/watterott/ATmega328PB-Testing (https://github.com/watterott/ATmega328PB-Testing)
Title: Re: ATmega328PB with Arduino
Post by: pv-tronics on May 14, 2016, 09:31 pm
I have made a bunch of development boards for the 328PB. They were designed around the port changes to accommodate the second uart. If anyone is interested, I have built up a few with all components on the boards.

here is a pic link:
https://www.flickr.com/photos/22368471@N04/26886993072/in/photostream/
Title: Re: ATmega328PB with Arduino
Post by: PaoloP on May 15, 2016, 09:15 am
Why use an old layout? duplicate SDA, SCL and IOREF is missing.

Layout of Elektorino Uno R4 in better.  ;)
(https://www.elektormagazine.com/assets/upload/img/public/original/prototype-1s.jpg)
Title: Re: ATmega328PB with Arduino
Post by: westfw on May 15, 2016, 11:53 am
Sigh.  I would have like to see the second I2C port get routed to the existing (R3) SCL/SDA pins (and a modifed "wire" library.)   That would free up all the analog pins while allowing simultaneous i2c on existing R3-compatible shields.  (alas, with compatibility problems.)