need i2c help (wii nunchuk)

Discussion in 'General Electronics Chat' started by ionymous, Feb 16, 2010.

  1. ionymous

    Thread Starter New Member

    Dec 8, 2009
    I am trying to interface a Wii nunchuk to a ConnectBlue OEMSPA311 bluetooth module. It's not quite working, and I could use some suggestions.

    First, here is my set up:
    This ConnectBlue module is typically used as an rs232 to bluetooth adapter, but ConnectBlue offers firmware to use it for i2c. I'm using this firmware.

    The Wii nunchuk uses i2c, and many people have connected their microcontrollers to it successfully.

    I am using my own windows program on my bluetooth enabled laptop to communicate to the ConnectBlue module.

    I have a digital compass IC that uses i2c, and I HAVE successfully connected and communicated with it through the ConnectBlue module.

    I feel confident that I have the correct i2c address (0x52) for the nunchuk, because the ConnectBlue module gives me back good messages. If I give the ConnectBlue a bad address or if I disconnect the nunchuk, the ConnectBlue module sends back an error.

    The problem is, when I read the 6 data bytes from the nunchuk, I get back FF FF FF FF FF FF.

    I have seen many examples of how to communicate with the nunchuk. Init by sending 0x40 0x0, then to read send 0x00 and read 6 bytes. Some people put delays in places. I've tried the examples and many variations, with varying waits.

    Now I'm wondering about the pull-up resistors.
    I am a software engineer, and electronics at this level don't come easy.

    I understand that for i2c I should use pull-up resistors on SDA and SCL. I did this for my digital compass, and it worked well.

    But maybe it is more complicated with the nunchuk. I've read that it already has built in 1.8k resistors on each line, and my ConnectBlue says it already has 47k resistors on each line. (47k because those lines are uses for rs232 normally, but I'm using i2c firmware as I mentioned above). The ConnectBlue document says I might want to use a 2.2k resistor on each line.

    I've tried a variety of resistors, 2.2k, 10k, 4.7k, and none.
    But I'm just doing so without understanding it well or doing any math or anything.

    Once I even used the 2.2k resistors as pull-DOWN resistors. Instead of reading 6 FF's I read 6 00's, which I guess makes sense.

    So in summary, I'm confident I can communicate well with the ConnectBlue module, and I can read data from one i2c device (digital compass).
    And I'm confident I'm communicating with the nunchuk, but....
    either I'm not communicating to it properly or my pull-up resistors are a problem.

    Can someone help me determine the proper pull-up resistors given that the nunchuk and ConnectBlue module already have some? Do I need to add or remove some?

    Thank for any help!
    (and sorry for writing a book. I hope it is actually helpful)
  2. kdillinger

    Active Member

    Jul 26, 2009
    I am assuming that the way your bluetooth module and the Nunchuck connect together simply place the pull up resistors in parallel **IF** they are being pulled up to the same voltage.
    Assuming this to be true and assuming that you are correct in your code, the parallel value would be 1.75k.
    What I suspect is that you are violating one or two things, possibly both. The first rule is that you must size the pull ups according to the bus capacitance in order to meet the rise time requirements in the I2C specification. I do not think this is the problem since 1.75k and a low bus capacitance more than likely will not violate the rise time requirements (I think they are 1us for 400 kHz operation). There are higher speeds so it could be an issue, but it would require some digging into the spec and running some calcs.
    The second issue is that with a 1.75k resistance, you may be violating the sink current specification of the bluetooth module. It states 47k resistors, so I am thinking that it cannot sink a lot of current and you are screwing up the logic thresholds.
    The other issue is that the bluetooth module and nunchuck may have different voltage rails their pullups are going to. Like the bluetooth module may be 5V while the nunchuck is 3.3V and things will definitely be screwy. There are I2C bus translators if that ends up being the problem.
    Can you verify the voltages of the I2C rails for each device, and is it possible to know what the sink current is for each module?

    That is my 2 cents at this hour. Maybe other members will comment.
  3. ionymous

    Thread Starter New Member

    Dec 8, 2009
    I am powering both the BT module and the nunchuk with the same 3.3v power source. I believe the pull-up resistor that I am adding is in parallel. Here's how I have it: My SDA and SCL wires go from the BT module to the nunchuk. Somewhere along each of those wires I have a resistor branching off the wire to the +3.3v.

    I will have to try this tonight. I'm willing to try many resistor values if it might help. I've already tried no additional resistor and 2.2k. Since 1.75k is fairly close to these, I don't have much hope. But again, my understanding of this and electronics in general is not strong.

    The nunchuk is normally run at 400khz. I've been running my BT module mostly at 100khz, because my digital compass can't do 400khz. Eventually I'll want to use these together on the same bus, but for now I've disconnected the compass. But I'm still generally using 100khz. I've used 400khz once or twice in the hopes that I might see some good values from the nunchuk. But generally I've been using 100khz since that is my end goal.

    Just to be certain we are on the same page, the 47k resistors are internal. The document says:
    "Serial Select 0: I2C Serial Data (SDA). The SDA pin has a 47kW internal pull-up to VCC (2.9-3.1V). Normally, a 2.2kW is more common in I2C applications and a 2.2kW external pull-up could be used if necessary."
    (same comment for SCL)

    For the BT module, the only thing I can find about sink current is:
    "IGPIO Sink and source current Max 4 mA"
    "V IN High Max 3.35 V"

    This is in a table titled "Input/Output Signals". But I'm not certain the SDA and SCL fall into the category of "GPIO". I guess. But "GPIO" is only referred to in one other place in the document referring to 3 optional LED outputs.

    I can try to research more about these parts if needed. Let me know if it is.

    Thanks for any attention you can give to this! I getting more hopeful that I'll get past this road block.

  4. ionymous

    Thread Starter New Member

    Dec 8, 2009
    I tried 1.75k tonight (actually 1.78k) with many variations of code. I still get all FF's.

    I sounds like someone using lego mindstorms had some issues with i2c timing. So maybe my BT module has some timing issues. I don't have low level control over it, so that might be a problem.

    I have a USB digital scope that I might have to bust out. If I can see the wiimote talk to the nunchuk, and then see my BT module do the same, maybe I can see something significantly different.

    I'd really rather not have to do that. So any other suggestions are welcome. It will take me a while to find enough concentrated free time to do it.
  5. ionymous

    Thread Starter New Member

    Dec 8, 2009
    Both the BT module and nunchuk are being powered by the same 3.3v power supply.

    But since the ConnectBlue document says the SDA and SCL "pin has a 47k internal pull-up to VCC (2.9-3.1V)", technically it is not true that the BT module and the nunchuch are being pulled up to the same voltage.

    So they ARE slightly different voltages.
    The BT module's lines are being pulled up to 3.0v by 47k resistors.
    The nunchuk lines are being pulled up to 3.3v by 1.8k resistors.
    (technically I'm assuming the nunchuk uses the 3.3v I'm giving it, and doesn't regulator power to a different voltage)

    How does this affect the pull up resistors I should use?

  6. kdillinger

    Active Member

    Jul 26, 2009
    Then sink current would be 63uA. It would be 1.9mA assuming the same 3.3V rail and 1.7k resistors (parallel value). Both are below the 4mA you stated earlier, but if they are different voltage rails then this should not be the issue.

    Can you verify the voltage rail on the nunchuck with a volt meter? The problem sounds like you may have a logic translation problem, but 3V and 3.3V LVCMOS should be able to talk to one another although you have little margin.

    The BT module is 3V so Voh is 3V assuming the leakage of the SDA and SCL lines are low (which they should be). Vih for the nunchuck is close to 2.31V assuming 3.3V*0.7. So this means the output high voltage of the BT module does exceed the Vih of the nunchuck for a valid logic high. Unless the nunchuck is powered by a lower voltage (doubt it).

    This is where a scope capture of the SDA and SCL lines would be nice long with a schematic or at least a hand drawn representation of the circuit.