Compiler errors for device atmega328PB but works for atmega328P

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All

 

I have been having trouble lately when compiling my programs in atmel studio 7 when the atmega328PB device is selected and I have included header and C files to my project. The problem will strangely go away when I change the device to Atmega328P. If I do this, the program compiles without any errors however every time I want to flash the atmega32pb then when I open the programming menu (Ctrl Shift P) then I need to change the device back to atmega328pb before flashing or else I get a signature error. 

 

This error happened to me a while ago then strangely stopped and everything was working. It now started again and i cannot find the problem. It only happens when i have included C and h files. If i have not included any additional files other than <avr/io.> and delay then it compiles without errors when the atmega328pb device is selected. See pictures below:

 

 

 

 

This topic has a solution.
Last Edited: Tue. May 19, 2020 - 04:29 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

When I build for 328PB then look at iom328pb.h under "Dependencies" I see:

#define TWSR0   _SFR_MEM8(0xB9)
#define TWPS0   0
#define TWPS1   1
#define TWS3    3
#define TWS4    4
#define TWS5    5
#define TWS6    6
#define TWS7    7

#define TWAR0   _SFR_MEM8(0xBA)
#define TWGCE   0
#define TWA0    1
#define TWA1    2
#define TWA2    3
#define TWA3    4
#define TWA4    5
#define TWA5    6
#define TWA6    7

#define TWDR0   _SFR_MEM8(0xBB)

#define TWCR0   _SFR_MEM8(0xBC)
#define TWIE    0
#define TWEN    2
#define TWWC    3
#define TWSTO   4
#define TWSTA   5
#define TWEA    6
#define TWINT   7

so it looks like they have given ordinal numbers to the TWI peripheral (does it contain more than one perhaps? Or maybe this is just "future proofing"?)

EDIT: answering my own question:

#define TWSR1   _SFR_MEM8(0xD9)
#define TWPS10  0
#define TWPS11  1
#define TWS13   3
#define TWS14   4
#define TWS15   5
#define TWS16   6
#define TWS17   7

#define TWAR1   _SFR_MEM8(0xDA)

#define TWDR1   _SFR_MEM8(0xDB)

So, yes, it looks like it now has more than one TWI and they are called TWI0 and TWI1

Last Edited: Tue. May 19, 2020 - 04:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

328PB has two TWIs, so the numbers 0 and 1 are added to TWxx.
For example, "TWSR" must be rewritten as "TWSR0".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PS what made you think the 328PB was identical to the 328P in the first place? There must be some reason for the "B". There's probably a chance that there is a "328P to 328PB" migration note from Atmel/Microchip. They always used to do this in the past for "derived" new models (that often added some features as appears to have happened here)

 

EDIT: ah ha....  https://www.pololu.com/file/0J1464/Atmel-42559-Differences-between-ATmega328P-and-ATmega328PB_ApplicationNote_AT15007.pdf

Last Edited: Tue. May 19, 2020 - 04:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Clawson. I cant believe i never saw this. Even though the output told me. No excuses for this one.