ATMEGA328PB - setting up a TWI slave

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

Hi guys,

 

using the ATMEGA328PB as TWI master works fine with Peter Fleurys lib on TWI bus 0.

But trying to set it up as slave, seems to be a little complicated, as it has 2 TWI busses and I did not find any library to manage this.

I've already read this thread, https://www.avrfreaks.net/forum/... but I find it just more confusing.

 

I didn't even manage to start the init function, as the compiler doesn't seem to know TWAR0 and TWCR0, although there is no red underline.

Removing the '0' (TWAR, TWCR) , there are no errors but this doesn't work either ...

Any ideas what noobie mistake I made this time?

Is using ISR(TWI0_vect) OK then?

 

Many Thanks!

 

 

 

 

Attachment(s): 

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

....I found out, that  iom328pb.h  contains TWAR0 and TWCR0, but I still don't know how to include it instead of  io.h.

Replacing it, there's    #error "Attempt to include more than one <avr/ioXXX.h> file."

And I really don't know what this is about (iom328pb.h):

#ifndef _AVR_IO_H_
#  error "Include <avr/io.h> instead of this file."
#endif

#ifndef _AVR_IOXXX_H_
#  define _AVR_IOXXX_H_ "iom328pb.h"
#else
#  error "Attempt to include more than one <avr/ioXXX.h> file."
#endif

Any help would be appreciated!

Thanks!

 

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

You need to add the device pack for the 328pb.

 

See this thread for instructions on updating a command-line tool chain.

 

--Mike

 

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

OK, one thing more I found out.

The io.h seems to load the correct ioXXX.h file depending on the defined device automatically, so I had a look a the Toolchain.

Although the ATMEGA328PB is selected, it shows the ATMEGA328P in the Toolchain (which has been used before with this software).

 

Any ideas how to correct this?

 

Many thanks!!

 

 

Attachment(s):