AVR 2 AVR over TWI

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

I'm working on AVR 2 AVR comunication over I2C (TWI). Could anyone help me out?

Master would be ATmega128, and slave would be ATmega32. I have a lot of headache just to send some bytes from one to another...

They both run on 7.3728MHz...

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

Using the USARTS would be easier. IIRC I2C requires you to set up address' on the slave. I don't use the TWI very much so don't take my post to seriously. If the meg32's usart is not going to be used then I would go with using one of the m128's to connect to it. Might make the code easier too.

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Agreed, using TWI requires more programming since there is no errorhandling in HW, so all errorhandling has to handled in SW. But if you carefully read the manual or find some I2C manual online you'll get it working, I'm sure.

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

Yes, I know. But 2 UART's on mega128 is used for other things (GPRS and GPS)... So I have TWI left for connection to PC...

I did some comunication inbetween, but with much trouble, very unstable, and I was hoping that somebody already has done this...

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

I have found VERY HELPFUL document on the web:

http://www.robotroom.com/Atmel-AVR-TWI-I2C-Multi-Master-Problem.html

The guy have found an issue with AVR TWI hardware. Does anybody know this guy/or have the complete TWI code instead of just this issues?

It would be a great start...

Anyway, I would try to deal with this issue next week and would post some results..

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

The article is about multimaster issues, but since you only have one master and one slave you shouldn't be concenred about multimaster issues.

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

mr_g wrote:
I did some comunication inbetween, but with much trouble, very unstable, and I was hoping that somebody already has done this...

What kind of problems are you having?
There are code examples in the project section.
What language are you using (asm or C)?
What compiler are you using?

http://www.mil.ufl.edu/~chrisarn...

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

Do you have pullup resistors on SCL and SDA? If so, what value?

Don

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

As a test, I set up a Mega8 TWI to a Mega32. I think it is very easy to do one way (master to slave)but I did not have the Mega32 slave send any data back. It was just a simple test. Although I had the Mega write to two different devices, the Mega32 and a I/O 8 bit expander chip located on the Mega8 board. So, it should be easy if only one way communications.

I'll believe corporations
are people when Texas executes one.

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

Well, it would be multimaster situation (2 for now).

Overview: I have been working on some embedded systems like GPRS/GPS/CAN based alarm systems. I have ATmega128 with both UARTs occupied for other things, but still need some good communication port for connecting my embedded system to a PC for monitoring, debugging and AVR's memory programming... I was using SPI for some time, but it is not a good solution...

On the other hand TWI (I2C) seems nice. It enables even more embedded systems connecting on the one network and monitoring them all over a single I2C network..

So I have a small ATmega32 connected to a PC over UART, where it acts like a interface between AVRs and PC.... I was able to send a byte or two, but after that everything would go to the hell. So, I was a furious after spending a week and done nothing. So I have put this project to a side for a few months.

Now, Founding out that post with the same issue but with the result, it gave me a energy to revive my old project.

So I was going to build a bootloader also, that would act as a I2C slave flash memory. Bootloader code would emulate simple I2C flash memory (slave) to enable simple programming over I2C, and I would put a code inside my embedded application for monitoring/debuging (Master/slave), so application can send monitoring/debugging code to the PC over interface AVR, and vise verse.

So, as you can see, this isn't simple master-slave situation, more like master/slave-master/slave situation.. :)