chipKIT® Development Platform

Inspired by Arduino™

Fubarino mini I2C

Created Tue, 15 Apr 2014 21:59:20 +0000 by sfugarino


sfugarino

Tue, 15 Apr 2014 21:59:20 +0000

Just received my mini. Much to my surprise it got here overnight. I haven't had much time to play with it, but I got a little confused reading the information about PPS. I need to set up I2C for an 9 DOF IMU. I can use the Arduino code for the IMU on my Chipkit UNO32 without any modifications. What do I need to do for the mini to setup the pins? Are there any I2C examples?


EmbeddedMan

Wed, 16 Apr 2014 01:29:41 +0000

I guess I"m ashamed to admit it, but I've never tried I2C (Wire()) on the Fubarino Mini.

The main I2C port is on pins 25 (SCL1) and 26 (SDA1). And when running the simple "master_writer" Wire example sketch, I don't get any action on those pins.

So something is clearly amiss. I am looking into it right now and will let you know what I find.

*Brian


EmbeddedMan

Wed, 16 Apr 2014 01:31:43 +0000

Oh, and you don't have to worry about PPS for I2C (Wire())). Because the I2C pins are kinda analog-ish, they can't be mapped through PPS. So they are hard-wired to RB8 and RB9 on the PIC32MX250 (Arduino digital pins 25 and 26). So PPS doesn't come into the equation at all for I2C.

They should just work. But clearly they don't.

*Brian


EmbeddedMan

Wed, 16 Apr 2014 04:26:58 +0000

OK, I've verified that Fubarino Mini I2C is functioning. However, you have to be careful with the address that you write to. I was using the example called master_writer that comes with MPIDE, which writes to an address of 0x04. On PIC32, you can't ever write to any address below 0x09.

Here's the code that I just tested on my Mini. This is with the latest MPIDE release, and I'm looking at pins 25 and 26 of the Mini with my scope, and seeing valid data coming out.

#include <Wire.h>

void setup() {
  Wire.begin();
}

byte x = 0;

void loop() {
  Wire.beginTransmission(8);
  Wire.send(x);             
  Wire.endTransmission();   
  x++;
  delay(500);
}

I did some detailed study of the datasheet. And I'm quite confused why we can't write out on addresses 0x00 through 0x08. I realize that these are 'reserved' addresses, but I have made sure that the STRICT bit in I2C1CON is clear. According to the datasheet this means we should be able to write out on any address. But yet we can't. There is no errata that describes this condition.

In any case, as long as you say above address 0x08, (and below 0x78) you should be OK.

*Brian


sfugarino

Wed, 16 Apr 2014 04:37:55 +0000

I2C usually requires pull up resistors on the SCL and SDA lines to work. Do the I2C pins on the mini have internal pullups or can they be configured with pullups? Arduinos, or rather AVR chips, have internal pullups, so no external pullups are needed. I also didn't need pullups when using a chipKit Uno32 either, although, I'm not sure why. Maybe the jumpers take care of it, but I really don't know. I've even used I2C on Netduino with success, but had to toggle the SDA line to get it to work. Don't understand that either, but it works every time on my Netduino. Oh gosh, I believe the IMU I'm using has pullups....

Just saw your post Embeddedman, so disregard the rest of mine. Thanks.


sfugarino

Wed, 16 Apr 2014 05:37:55 +0000

[url]http://i2c.info/i2c-bus-specification[/url]

The allocation of I2C addresses is administered by the I2C bus committee which takes care for the allocations. Two groups of 8 I2C addresses are reserved for future uses and one address is used for 10-bit I2C addressing.


sfugarino

Wed, 16 Apr 2014 08:50:37 +0000

Bryan,

Please excuse my ignorance, I didn't realize who I was talking to. Kudos on the SD and mini. These are really nice little boards. I'm using that mini to recreate an ArduIMU for a boat project. Was using an Arduino Pro Mini 328, but the mini is far more capable and the extra UART is going to be very helpful.

Sam Fugarino

That's really my last name, but had nothing to do with why I bought a Fubarino. I already have a chipKit Uno32 which I like a lot.


EmbeddedMan

Wed, 16 Apr 2014 13:05:54 +0000

Sam,

AWESOME last name. I'm so jealous. :-)

The Fubarino Mini and Fubarino SD do not have any pullups on the I2C lines (on the board anyway). I suggest just adding them externally (that's what I did for my testing last night - two 4.7K ohm resistors to 3.3V).

And yes, the addresses listed in the chart are the ones that the PIC32 cannot be made to send on. I do not know why. It's pretty important that it can send to those addresses - I tried everything I could think of last night, and it just wouldn't.

I've sense updated all of the example sketches distributed with the MPIDE version of the Wire library to use addresses outside of that range. Hopefully that will help other people who have the same issue I did.

Now back to your problem. If you run the sample sketch I posted on your Mini, (with pull ups) are you able to see some clock and data happening?

*Brian


sfugarino

Thu, 17 Apr 2014 20:19:54 +0000

I hooked up my IMU, but haven't gotten it to work, but I'm using pins 9 and 10. Going to try 25 and 26.


sfugarino

Thu, 17 Apr 2014 20:34:49 +0000

After switching to Pins 25 and 26, the IMU started to send data. I'm using Adafruit's 9 DOF IMU, but am running Pololu's software because it includes a DCM filter. The only changes need to run the software are to remove the includes for Arduino.h.


EmbeddedMan

Thu, 17 Apr 2014 20:58:01 +0000

That's fantastic! I'm really glad you got it to work. Best of luck on your IMU project - and keep us up to date with your progress.

*Brian


sfugarino

Mon, 12 May 2014 06:29:17 +0000

I get everything to work on pin 25(SCL1) and 26(SDA1). When I switch to 9 (SDA2) and 10 (SCL2) I2C doesn't work. Am I missing something? I can get by using 25 & 26, but they are also the TX/RX pins for Serial2. I may need that port and to be honest, not getting 9 & 10 to work is just bugging the hell out of me. Any ideas?


EmbeddedMan

Mon, 12 May 2014 17:02:38 +0000

Hmm. I got those pins to work when I tested it, I think. Did you switch over the defines in hardware/pic32/variants/Fubarino_Mini/Board_Defs.h? (the ones at the bottom that start with TWI) In order to get the second I2C port to work, you'll need to switch all of those defines over from I2C1 to I2C2. I think that's all that's necessary.

*Brian


sfugarino

Tue, 13 May 2014 00:17:34 +0000

Thanks Brian

What is Digilent DTWI library? It has defines for both I2C1 and I2C2.

Latest version of the IMUle

Would rather use a ublox lea 6. Also might switch to a MPU 9150. I'd really like to have a Fubarino SD with a 9150 or 9250 on the board. That would be very cool.


sfugarino

Tue, 13 May 2014 03:57:30 +0000

That worked! Thank's Brian!.


EmbeddedMan

Tue, 13 May 2014 12:20:10 +0000

The Digilent DTWI has yet to be written, unfortunately. It was supposed to be a library that allowed a sketch access to as many I2C ports as your board had, at the same time.

*Brian


sfugarino

Tue, 13 May 2014 15:18:17 +0000

It just occurred to me that one has to set the jumpers on the UNO32 in order to access one I2C port. I assumed that was to put the I2C port on the same pins as on the Arduino.

It's no big deal for me anyway. I'm glad that I could free up pins 25 and 26 for UART. I was going to port the ArduIMU code over and the three serial ports are nice to have. One talks to the GPS, one to an Ardupilot legacy, and the USB is free for programing. I'm starting to back off the ArduIMU code or at least the DCM in favor of a Madgwick or Kalman filter. Probably ought to breakdown and buy a Pixhawk, but seems like overkill for a boat. Well, so is calculating pitch and roll., but this is really a learning exercise, so why not.