Looking for help with i2c(TWI).

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

I have a good grasp on how i2c works but need help with detail to troubleshoot my application. I love hardware base protocols when they work but when they don't it's a pain to fix.

 

My issue is I'm not always getting the ISR to fire and when I do, I get a error (0x00). I'm also not sure what makes it fire as most of the time it does not. I though it watches for SDA to fall followed by clock (start).  I have set up a basic slave to talk to a known master (wii-mote). It does use i2c its the normal form AFAICT using 400kHz "fast" I2C, with slave address 0x52. I see on the scope that the master sends its address and data constantly. I can set up my slave to read the data but either my app seems to freeze once I enable the interrupts or I get 0x00 in ISR.

 

So questions are;

1)    What part of the message triggers the ISR? Start bit or end bit? It looks like my scope triggers on start bit when it does. If it should trigger on stop bit, is there a significant delay before the IRS is called.
2)    What could ause a buss error (0x00). My scope shows the wave form correctly, I see nothing wrong with it.
3)    Why would I get a ISR event sometimes, other times all communication just stops, or the lines goes dead (SCL low SDA high)  as soon as I enable my interrupts.

Observations, I see the master sending a write at 0x58 of 37. Then I see a read at 0x58 of 0xff ( 7 more FF's). Guessing this is all specific to the use case of the master. Then it repeats endlessly. I start my slave and after the set up and starting my interrupts I get one of 3 conditions.

 

1 SDA line is high SCL is low and nothing changes, app seems to be frozen

2 Master continues to talk but my app seems to be frozen. 

3 I get a reply from ISR of 0x00 then my app seems to be frozen. 

 

I'm not sure what makes my results change but does not seem to be random. I'm using know working code examples. Nothing special going on there but happy to show the code if that is asked for. I just feel there is more of a hardware issue here.  Happy to provide more info about the master and the wiring.

 

In the simplest sense I'm doing this.

 

twi_ddr &= ~0x03; 
twi_reg_addr = 0;
TWAR = addr << 1;
TWSR = 0;
TWBR = ((F_CPU / 400000) - 16) / 2;
TWCR = _BV(TWIE) | _BV(TWEA);

TWCR |= _BV(TWEN);
sei();

After the sei command I get nothing further from the code.

 

Other details.

Using an atmega32u4

Master is a Nintendo Wii-mote

Data is encrypted and runs at 400Hz

The project I'm using is found here.  http://code.google.com/p/circle-...

I'm not using any external pull ups as the mega MCU is pointed out to be enough.

 

 

 

 

 

 

 

 

 

 

 

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

If you look at figure 20.10 in the data sheet for ATmega32u4 (mine dated 04/2016) it shows where TWINT is set.  If you look at the register description for TWCR bit zero it says at long as TWINT is set the interrupt is active.

Last Edited: Fri. Jan 22, 2021 - 01:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

S_K_U_N_X wrote:
I'm not using any external pull ups as the mega MCU is pointed out to be enough.

Ah, the datasheet says that the IO pullups are between 20k and 50k. A simple test would be to put a 3.3k on each line and see if that helps.

 

"If you find yourself in an even battle, you didn't plan very well."
https://www.gameactive.org
https://github.com/CmdrZin

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

S_K_U_N_X wrote:
I'm not using any external pull ups as the mega MCU is pointed out to be enough.

Where is that "pointed out" ?

 

As  CmdrZin says, internal pullups are going to be way too high.

 

This is where looking at the wires with an oscilloscope would show you immediately what's going on ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
looking at the wires with an oscilloscope
+1000

 

When using "hardware protocols" there's nothing quite like watching a bit of "wire wiggling" to be sure what you are doing on the software side really is happening out on the wires. I'd say a scope (or at least a logic analyser) were fairly vital for I2C. Also useful when doing SPI or UART in fact, but even more benefit for I2C.

 

(a decent scope and probably all logic analysers will likely have a "protocol decoder" that knows how to interpret I2C wire wiggling to show it at a higher level - per byte transmission)

Last Edited: Fri. Jan 22, 2021 - 09:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Using the TWI peripheral as God had intended makes I2C a breeze.    No need for LA, scope, ...

 

I'm not using any external pull ups as the mega MCU is pointed out to be enough.

shows that the OP is determined to fail.

 

David.

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

david.prentice wrote:
  No need for LA, scope, ...
Until it doesn't work and you want to know why!

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


david.prentice wrote:
Using the TWI peripheral as God had intended makes I2C a breeze

But still requires that you get the external hardware right - in particular, the pullups

 

david.prentice wrote:
  No need for LA, scope, ...

clawson wrote:
Until it doesn't work and you want to know why!

Absolutely!

 

Especially if the reason it's not working is something "analogue" - like the wrong pullup value.

 

EDIT

 

From https://electronics.stackexchange.com/questions/1849/is-there-a-correct-resistance-value-for-i2c-pull-up-resistors/473799#473799:

 

 

So, with a scope, you can see immediately if you have a problem with the pullups.

 

This may not be so clear with a logic analyser which, as the name suggests, just shows you how it has interpreted the analogue levels into digits.

 

A logic analyser (or protocol analyser) is generally better once you got these basics sorted and want to concentrate on the message content.

 

#I2CScopeAnalyser #I2CPullups

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Jan 22, 2021 - 10:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

david.prentice wrote:

I'm not using any external pull ups as the mega MCU is pointed out to be enough.

shows that the OP is determined to fail.

Indeed - despite:

S_K_U_N_X wrote:
I have a good grasp on how i2c works

frown

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Remember that the address bits are often mingled in with the R/W bit....always a fun day at the races if you forget (or everyone uses a skewed description of "address").

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

avrcandies wrote:
Remember that the address bits are often mingled in with the R/W bit

Indeed: https://www.avrfreaks.net/commen...

 

frown

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry if that was unclear somehow but I have a scope... OP says "I see on the scope that the master sends its address and data constantly. "

 

Also here is where no pull ups came from.
https://www.raphnet.net/electron...
I'm not using this design but this design used most of the same hardware.

Specific note was made here
https://www.raphnet.net/electron...

 

I know that project works, so I didn't bother messing with it. I shall give the 3.3 a try though.

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

S_K_U_N_X wrote:
I have a scope

How about posting some traces, then?

 

Also here is where no pull ups came from.
https://www.raphnet.net/electron...
I'm not using this design but this design used most of the same hardware.

Specific note was made here
https://www.raphnet.net/electron...

Searching both of those pages give zero occurrences of the word "pull"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry second link was meant to be this

https://www.raphnet.net/electron...

 

Yeah I have a few traces I can upload (will attach to this post).

I added a scan that shows when I turn on my interrupts (top white line going high). All data just stops. I also blew up one of the masters writes. Happy to grab anything else that may be needed, but the analyzer clearly shows it's well formed. 

Attachment(s): 

Last Edited: Sat. Jan 23, 2021 - 10:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, the datasheet says that the IO pullups are between 20k and 50k. A simple test would be to put a 3.3k on each line and see if that helps.

Seeing the same results or at least one of the 3. In this case I do once again see the ISR trigger but the error received is still 0x00. 

 

 

Again as many pointed {using a scope} but I am, and it looks fine. Attached a trace but the issue seems to be that the AVR is not read the signal right. Also agree it sounds very hardware like but I have everything as it should (or so far as I can tell). 

 

Remember that the address bits are often mingled in with the R/W bit....always a fun day at the races if you forget (or everyone uses a skewed description of "address").
 

but I'm not at that point yet right? This is the first time I have tried to make a salve for i2c, and it looks like I'm not getting what I'd expect. My entry point for software is the ISR and all I get is 0x00. 

 

 

 

 

 

Last Edited: Mon. Jan 25, 2021 - 11:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:
Again as many pointed {using a scope} but I am,

 

In post #14, a logic analyzer image is attached, but that is not what we want; we want to see the shape of the signals' rise.

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

ah, very good them. I thought most were saying an analyzer was better. Come to think about it I have an analyzer that also has analog, ill use that and report back.

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

Ok, with the 3k pull ups I see a max voltage of about 2v. IIRC that is teetering on the edge. The connected master does use 3.3 but from reading about it online it is 5 volt tolerant. I do have a 3.3 to 5v level shifter layout around I could try.

 

Attachment(s): 

Last Edited: Tue. Jan 26, 2021 - 02:36 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using the level shifter I can only conclude that maybe the clock signal has issues keeping up.

 

To explain in images. The scope is on the +5 end of the level shifter. At the highest point I get 2.5 and the lowest a few mv. It does pull up to 4.9 at rest. This Level shifter was for another project, do I just need to find a better pull up balance here?

 

 

EDIT: 550ohms give my highest peak a 2.8 I'd think that would work with the AVR. But my symptoms from above remain.

 

 

 

Attachment(s): 

Last Edited: Sat. Jan 30, 2021 - 06:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any chance some other device is connected to the SCL or SDA lines? Can you try to use other Slave devices or try the Slave on a different Master?   

Looks like it's time to break up the system into parts and test each separately to isolate the problem.

 

"If you find yourself in an even battle, you didn't plan very well."
https://www.gameactive.org
https://github.com/CmdrZin

Last Edited: Sat. Jan 30, 2021 - 06:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One thing is for sure; the signals do not look like your logic analyzer is showing. Post #8 shows different ways they might look, and in all cases, the falling edge should be sharp. The level shifter does not help with the rising edge but allows one side to rise to 5V while the other is limited to 3V3. If the 10k resistors are missing on the 3V3 side, the 5V side will only pull that voltage up to 2V3 due to the 1V cutoff (BSS138 typical, it varies +/- 0V5).

 

The level shifter is not an easy circuit to understand; I used a SPICE simulator a few years back to learn it. There are quite a few around; an easy one that I liked was everycircuit, but the free version only allows five elements, not enough for this circuit.

 

https://everycircuit.com/

 

I am not a fan of just wiring stuff up and think I understand it. If you do use SPICE, you will need to study how a MOSFET works to learn how to set the parameters in SPICE, then simulate the pull-down with a switch (maybe a push-button) and look at the wave to learn what it should look like in theory. Then build the circuit and test the theory.

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

For lvl translation I usually go with this circuit. 2 resistors and a mosfet

Attachment(s): 

Last Edited: Sun. Jan 31, 2021 - 01:53 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I2C is an open drain pulldown and a resistor pullup. You could use a push button to short the signal line to the ground or have the pulse source turn on a transistor that pulls it to the ground, but the pulse source directly driving the signal line is not valid.

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

I'm still thinking the entire thing is code or twi related. For a simple test I did this.

 

DDRD = 0;
if (PIND & 1)
{
    PORTF |= 0x01;
} else PORTF &= ~0x01; 

Result attached.

 

Maybe I'm think in the wrong pattern here but does this not tell me the avr is capable of reading the wave form? If so why can't the twi read it?

 

 

 

 

Attachment(s): 

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


Go on - you know how to put a picture in a post - where we can see it:

 

 

So what are those 2 wavy lines at the bottom?

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that is the wave forms from an analog probe. If that's true something is wrong cause the bottom two lines should look more like the top two.

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

Can you post a picture of your setup? Also set 1 pin you are not using as an output high and put a meter on that pin, do you see 3.3v?

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

Kuch wrote:
If that's true something is wrong cause the bottom two lines should look more like the top two.

Exactly - see #8 !

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I'm not sure how to put a picture in the post when uploading form my system. That would be a helpful tip.

 

The bottom are the analogs, shows volatage like the image in post 18. If those look wrong, maybe my analyzer is a poor scope when it comes to analog.

 

Kuch, no the AVR chip is at 5v logic, the master uses 3v.

 

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

S_K_U_N_X wrote:
That would be a helpful tip.

Take a look at the tips in my signature, below - Tip #1, in particular.

 

The bottom are the analogs, shows volatage like the image in post 18. If those look wrong, maybe my analyzer is a poor scope when it comes to analog.

Or actually it is showing you that your I2C lines are a real mess - which would entirely explain why you're having trouble with them!

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:

I'm not using any external pull ups as the mega MCU is pointed out to be enough.

awneil wrote:
Where is that "pointed out" ?

S_K_U_N_X wrote:
 link was meant to be this

https://www.raphnet.net/electron... 

which shows this:

 

Which specifically refers to the reset pull-up - it does not apply to the I2C!

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Feb 2, 2021 - 01:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Right but we are way passed that point? I have already learned no pull ups is unwise, I also used a level sifter to get things a bit easier to deal with. It has been pointed out that the wave form is not in good shape but I didn't think i2c require such fuss. I also see I want a sharper fall rate from the examples in this thread (post 9). Though I'm not sure how to get where I need to be. Resister values are not changing the wave fall rate, it only rises or lowers the voltage in a global way. I'm not sure what I need to do to get this wave form in better shape. I'm struggling to understand ron_sutherland 's posts about SPICE.  If I remove the level shifter the wave for is still very even like the images I posted. Though at this point I can verify the AVR deals with 3.3 just fine. Also for kicks, that raphnet schematic didnt use pull ups either.

So I'm thinking

 

1) nix the level shifter (its not helping anyways)

2) find a good pull up value that keeps the wave in a form the AVR can sens high vs low

3) find a way to make the wave form fall appropriately. (currently at a lose as to how to do this)

 

At this point the only thing touching the i2c lines is the master, slave, level shifter, and probs. I could remove the slave (AVR) and see if the wave changes any.

 

 

 

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

Just to add here my scope was sampling at 3 MS/s If I only watch two lines I get 6.25 MS/s and the resolution helps a bit. but anything 1-2 us apart does not allow the line to get back up to 5 volts.

 

ok lets try this image in post deal..

Last Edited: Tue. Feb 2, 2021 - 02:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:
I could remove the slave (AVR) and see if the wave changes any.

Yes - always start simple.

 

The first thing to do is to ensure that you can get a good, clean square wave at the desired speed.

 

Do that by just toggling an open-drain IO pin with pullup and nothing else. There's no point even thinking about I2C before this is solid.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, removing the slave shows no change. Still very round. I have a pretty heavy pull up. 500 ohm at the moment. I'll try a higher value and see if I get a more square wave.

 

 

 

 

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

S_K_U_N_X wrote:
Still very round. I have a pretty heavy pull up. 500 ohm at the moment.

Something seriously wrong there, then!

 

surprise

 

I'll try a higher value and see if I get a more square wave

The higher the resistance, the slower the rise - so that's not going to help.

 

You need to find out why it's so rubbish.

 

As well as minimal software, you also need to start with a minimal hardware setup.

 

Post you minimum but complete code, and schematic, and some good, clear, in-focus photos of the setup.

 

EDIT

 

Your picture in #33 shows both slow rise and slow fall - which is not what would be expected with an open-drain driver.

 

As shown in #8

 

Are you sure it's an open-drain drive?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Feb 2, 2021 - 04:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, lets do this. I set up a few harness to get this worked out.  Also stretched out my view so the wave is amplified a bit.

 

Here is a working set up, master and slave (not my slave, the one I'm trying to emulate).

 

 

Here I added my 1.5k pullups as a baseline. Also removed the slave.

 

 

 

 

Here I add my slave

 

I can see adding my pullups effect the rise but its not significant. Also the wave seems the same to me from working(original environment)  to not working(my set up). Does this wake form look right even in a working condition? Maybe this "wiimote" is not following i2c standards? There is proof that is can work.

Last Edited: Tue. Feb 2, 2021 - 11:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Those look much better then what you were posting before, now how does your program respond? Does the ISR fire? Do you receive what your LA is showing as being sent?

Edit:
After a closer look, your data line is better but your clock is out of whack. Did you put a pull-up on the clock line aswell?

Last Edited: Wed. Feb 3, 2021 - 03:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You've still got symmetrical  slow rise and fall - again, that's not what you'd expect with an open-drain drive.

 

Again: are you sure it's open-drain?

 

And how about posting the code you used, and the schematic and photos - so we can see the full picture. You're keeping us guessing in the dark.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it's the same wave as before, as I said I stretched the view more to see things better.

 

 

Again: are you sure it's open-drain? --  Isn't that part of the master? From the best I can tell it seems to be out and Low but I can't change anything about the master.  MY first image was nothing connected from the slave.  I posed the scan of the wave form in its working state but it looks just the same. You are still saying that wave form is incorrect so I can only assume this wii-mote does not follow standards. The AVR is not reading things right so my guess is I need to dress up the wave form somehow but rise or lowering the resistance is not change that.

 

I didn't write the code, it came from   http://code.google.com/p/circle-...  as indicated in my OP. I of course tried  playing with the code a bit to add some debug but the code I have when put back to its original state does not seem to be readable by the device.

 

The AVR is hooked up in a general sense for a test environment. Nothing touches the TWI lines other then a resister. It is powered by the 16MHz clock and +5 volts. I do not have any schematic on it yet as it is still in the design state. This is the board I'm using. https://www.adafruit.com/product...

 

 

 

 

 

 

 

 

Last Edited: Wed. Feb 3, 2021 - 09:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S_K_U_N_X wrote:
are you sure it's open-drain? --  Isn't that part of the master?

Yes, it should be.

 

I didn't write the code, it came from   http://code.google.com/p/circle-... 

That talks about the AVR being a Slave - not a Master.

 

I do not have any schematic on it yet as it is still in the design state.

So how on earth are we supposed to know what you have?

 

I can only assume this wii-mote does not follow standards

Is there are reason to suggest that it is a standard I2C interface?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That talks about the AVR being a Slave - not a Master. 

 This is what I have been saying. Original post " I have set up a basic slave to talk to a known master " and I think throughout ? Sorry if I made a mistake on that at some point?

 

So how on earth are we supposed to know what you have?

This is a common dev board (breakout board). I maybe could dig up the schematic. I'm trying to emulate the salve here.

 

Though I guess I have two issues here. 

1) The wave form is not acting like it should while my device is not connected to it, so my hardware is not relevant to that strange wave form.

2) My dev setup is not reading this wave form.

 

I can see how the two support each other in failing but that Rahpnet design (other then the MCU change) Is very similar. It somehow works with the wave form as is. I see no note about pull up restorers or any struggles to get it to work.

 

Is there are reason to suggest that it is a standard I2C interface?

 

The device was not designed to be used by i2c, it was used to be designed by their own mast slave set up. So be all means they could have used some substandard approach.  It is actually to their advantage and their MO, but everything on the net make no mention of this. As fact, all info says it is exact that, an i2c protocal in and out. Mayne expanses of an Arduino using and talking to it. I even made my own device acting as a master), talking to it's slave. The AVR (master in this case) makes a perfect correct and good wave form.

 

 

Flow chart of thinking...

I have a master that uses a distorted i2c wave form.

---> This is bad, never work with something that is broken.

----> but I can not fix it. Changing my pull up values does not change it. Must be getting some capacitance interference.

|

--->master device works with its slave mate

----->observed the same distorted wave form wile it communicates.

|

----->try that wave form the way it is on my emulated slave device, but it does not work. Can not read the wave form. Must fix wave form.

 

 

Should I put two conductors on it? Would get a delay but a global delay, will that fix my wave? ELI the ICE man suggests it might. I have no idea where to go next.

 

 

 

 

EDIT:

I also came by this, if its copyrighted please remove. I didn't see any notice of such.

(schematic of master device)

https://fccid.io/X5B-PL7602/Sche...

 

 

 

 

 

 

 

Last Edited: Thu. Feb 4, 2021 - 06:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're right - I have completely lost track.

 

I give up.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...