TWI mega to mega Master to Slave Issues

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

Hey Guys once again,

Mega644PA to Mega644PA on Atmel Studio
I've been scouting the forums most of today among a few other places and I can't seem to resolve an issue I've been having with basic communication between Master and Slave devices. Initially I thought It was my code Utilizing the most basic stuff I could create still created issues.

So I next moved to existing projects and tutorials starting off with http://pengu.student.utwente.nl/wordpress/?p=136. And still couldn't create a connection between the two units. Moreover, according to my oscilloscope a lot of data is being transmitted, however, no data was reaching the other end as I placed inline USART debug commands that did nothing.

I also tried "Fleury" I2C stuff which was supposed to work for almost anything and it couldn't even generate a pulse on the scope. Thus making me feel like my hardware setup is incorrect plainly my Slave was not working.

I tried my custom Slave as well as the one listed above and neither worked. My last try was with the Atmel Notes example applications, while I understand they weren't created for the GCC compiler I changed a few lines of code to be compatible withe the GCC compiler for both the master and Slave, compiled and uploaded and these together didn't work either.

I also understand that most of these applications have been made for varying tinyavr's and atmega based devices and in some cases like "Fleury" for a single operation for an external EEPROM device. I changed what I could to work, addresses so they matched both ends, and Ports when rarely used.

Would you guys know of any solid tutorials that I may have overlooked in my search, perhaps starting from scratch that could resolve what I have done thus far?

I am simply trying to get a data string to the slave device and output through USART.

Thanks ahead.

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

ryanafleming wrote:
Moreover, according to my oscilloscope a lot of data is being transmitted, however, no data was reaching the other end as I placed inline USART debug commands that did nothing.

The good news is that you have a scope to work with.

You said that the scope showed "a lot of data is being transmitted".

What is the circuit you are using.
Are the two microcontrollers on different boards?

Was the scope probe looking at the input to the receiving (slave) microcontroller?

Did you see an ACK (bit 9) from the slave?

Attached is an image showing address transmission with ACK/NACK response.

Attachment(s): 

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

Do you have pullup resistors on SDA and SCL?

Do you have a debugger to see for sure if the data is getting to the slave device?

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

Update: Started from Scratch again and im getting constant 0xF8's.

This apparently didn't post 12 hours ago =[
------------------------------------------
Chuck:
I can confirm data is being transmitted from the master as when i remove the plug from the slave in some cases data is still being transmitted according to the scope.

Based on the Image you have there, I am unable to actually test for the address MSB as the scope doesn't have a high enough sampling rate (or something along these lines...). As I am currently doing polling with no delays, the transmissions are continuous and it is too hard to find the start. If I introduce delays, even small delays it becomes hard to capture the data in time (pressing stop button). If I 'zoom out' by increasing the time/div so i can see it all on the one screen then stop and increase the time/div on the waveform, the scope doesn't have enough samples (like stated above) to see the square waveforms. Handheld scope...its good, but a pain with these things.

Both of the circuits are matched and this a new issue that has arisen in comparison to my last post

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=133563 which shows my circuit(ish) block diagram of what I am doing.

@Atomicdog:
I do have a pullup on both the lines, I am using a 2k res on both, link above shows circuit diagram. I don't have debugger though.

---------------
One other question just while I have you guys, when a transmission occurs from a slave, as the master creates the clock and only transmits when data it is transmitting data, how does it know to do the clock when the slave wants it? Does the slave pull it high/low letting the master know to create a pulse?

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

Quote:
One other question just while I have you guys, when a transmission occurs from a slave, as the master creates the clock and only transmits when data it is transmitting data, how does it know to do the clock when the slave wants it? Does the slave pull it high/low letting the master know to create a pulse?
The master just sends out the clock signal. If the slave needs more time it can use 'clock stretching'.

You can try slowing the clock speed way down so you can see it on the scope.

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

Interestingly enough I finally got the code working off http://pengu.student.utwente.nl/wordpress/?p=136 top stuff. Now sending through numbers through from 1-12 and im outputting them through USART.

Just have to adapt the code into my own form now! Thanks for all the effort in reading my excessively longs posts guys! =]

Quote:
You can try slowing the clock speed way down so you can see it on the scope.

Prescaler, just remembered yea! might have a crack to see it all on there.

Cheers mate!

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

Edit: Sorry, I didn't see you're latest post before posting this.

ryanafleming wrote:
One other question just while I have you guys, when a transmission occurs from a slave, as the master creates the clock and only transmits when data it is transmitting data, how does it know to do the clock when the slave wants it? Does the slave pull it high/low letting the master know to create a pulse?

The Master always generates the clock signal, SCL.
For the Slave to send data back to the Master,
the Slave recognizes its address and the r/w bit
is set high, (Master reads, Slave transmits).

The Slave then puts data, one bit per clock pulse,
on the data line, SDA, when the SCL is low.

The Master then releases SCL (which is pulled high),
waits until SCL is pulled high, then reads the data bit,
and sets SCL low again. This repeats until all the
data has been read.

If the Slave needs more time to fetch data, then
when the SCL line is low, it can hold the SCL line
low until it has placed the next data bit on SDA,
and then release the SCL line.

Wikipedia has a page for I2C (Link).

************

I looked at the thread you linked to, but I'm not sure that you resolved anything.

1) Are the two microcontrollers on the same board or different boards?
2) Do the two microcontrollers have a common ground?
3) What are the supply voltages for the two microcontrollers?
4) If you connect your scope to the SCL and SDA lines at the Slave, do you see clock and data signals?