atmega328p i2c slave mode selection

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

hi,

 

I am new here.I want to know how to set the atmega328p to slave mode.

 

I am connecting the atmega ice debugger to program the atmega328p.

 

Can any one help me which register i need to program to put into the slave.

 

What will be the slave address.I will connect aardvork as master and try to do i2c communication.Please anyone share me details.

 

Thanks in advance

 

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

Well, I2C requires far more then just setting a register, you will need a complete slave program.

M328's are more suited for master operation, but slave operation is do able with the right program.

Have you looked at using an Arduino, such as an Arduino Nano, libraries of I2C code exists for slave operation there.

Do you know what you want your slave to do? That is key to proper operation.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

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

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

thanks for the reply...

 

I want to make sure that i am able to read and write register.For sanity testing,I will be using aardvark to read and write register and data.

 

I want to test i2c operation from atmega to aardvark.

 

Can you please help me on how to configure the atmega as i2c slave mode and set address.

 

 

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

My old aardvark has an ATmega16 inside. Given that I would be more concerned with it working with stuff that was not an AVR.

 

I will point you at the Wire library, which can be used to make an I2C slave.

 

https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire/examples

 

If you want to use C (that is what I prefer), it turns out that Wire is just a wrapper for the C driver that lives under it. It takes just a little hacking to unwrap and then kaboom you have a reasonably well-tested C driver.

 

https://github.com/arduino/ArduinoCore-avr/tree/master/libraries/Wire/src/utility

 

For a complex example, I have a project where I use it as a slave for both I2C and SMBus on separate I2C channels (the SMBus host can power down without clobbering the other). I have them at different address so they can be on the same bus for testing/debugging.

 

https://github.com/epccs/RPUpi/tree/master/Remote

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

Maybe I'm the last one to have heard of it but in case anyone else has no idea what an "aardvark" is in AVR terms I rather suspect they are talking about:

 

https://www.totalphase.com/solutions/apps/avr/

https://www.totalphase.com/products/aardvark-i2cspi

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

Here is an image inside an aardvark; it is not much more than an Uno; mine is a professional dust collector nowadays.

 

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

The OP wrote

I want to make sure that i am able to read and write register.

 If the OP expects to access the internal AVR (hardware) registers via I2C, it will not happen without programming the AVR. This means more than just configuring the I2C/TWI interface. The OP will actually have to create a program to do this and load that program into the chip that is going to become the slave. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net