Sorry I've been so busy with work for the past few weeks, I haven't had a chance to work on this at all. I am happy to report that the new firmware does work with my PIC18F slave device, so, nice work!
The PIC18F slave device code I've written would work for a slave implementation on the bus pirate, I'll get to work on porting it over as soon as I have more free time. Sorry again!
Sorry, I've been kind of busy with work and haven't had time to figure out what's not working with my I2C code (with open drains turned on, it seems to always hold the line low, even if the tristate shouldn't be allowing that). I'll hopefully get a chance next week, but I can't promise anything right now.
I think I've found another problem, while reading the specs and some sites about I2C. I've noticed that your software implementation doesn't send a NACK after reading the last byte.
I've decided to rewrite the software I2C routines using the outline on this website. The size of the code drops by about 250 bytes with my new routines and they'll be licensed the same way as the rest of the BP code, which is nice. I've been busy over the weekend and didn't have time to test the code, but will have a chance in the evening tonight. Once I'm sure it's okay, I'll post the diff and hopefully we'll have something working properly.
For a simple logic analyzer, I use my PICKit 2. It's only good for signals up to 500Hz, but for a lot of hobby applications, this is okay. It's only 3 channel, but in a pinch, with hardware many already have, it's still useful!
On windows, Microchip's software works fine. On Linux/OSX, you can use my version of the tools, located at http://pk2-la.sf.net
This is the tool I'm using to figure out what's going on with the I2C issues.
I made it print the warning once per session, more seemed like overkill (I tried it a bit and it was annoying). Instead, I've made the user press 1 to continue despite the warning or 2 to cancel and go back to Hi-Z mode, hope that's okay.
Note, you'll have to add I2Cb.c to your project before committing, it's not currently in the project and doing so really changes the project file, so I figured I'd let you do it.
Okay, I've moved some code around a bit and added the revision variables to the bpConfig register. If this is okay, we can then use these variables to determine if the hardware is new enough to use HWI2C. The patch is located at http://dev.gentoo.org/~josejx/bus_pirate/procver.patch
This was the test I was running before. It works up to this point. If I follow this up with other commands, the device doesn't respond properly and continues each command as a read as observed by a dump of the internal I2C registers to an LCD on the PIC18F. It stays stuck (no stop rx'd) until I send a command that ends in 0's:
After this, I can write to the internal registers and start another read cycle. I'm not 100% sure where the bug is (in my PIC18F code or in the bus pirate) but it should be pretty obvious once I get the Logic Analyzer attached.
On a side note, I2C on PIC is harder than it initially appears.
Can you do as many writes as you want? Is it only reading that's screwing up?
On my PIC18F that I'm using as a test slave device, I am seeing reads miss the final stop bit (bulk or not). Sending a write with two 0's seems to fix it and let it work again. I missed this before because I was just testing a write followed by a read. :p
I will hook it up to a logic analyzer later today to see if it's properly sending the stop condition after a read.
I put a patch up to allow for the original clock speed and 10x faster using software I2C, ~5KHz and ~50KHz. I still haven't had a chance to measure it exactly, but will do so later today. Try it and see if the faster speed helps?
Another thought, does the device support "restarts" where the start command is given again without a stop for the last command? Does it work properly if you specify a stop command before the read?
I am also seeing some incompatibility with I2C and a random assortment of devices. One issue that I've found is that the software I2C routines clock at only about 3.4KHz, which is too slow for some devices. The hardware I2C routines mentioned in another post will hopefully fix this issue.
What speed is the device that you're trying to interface with?
Okay, so the HW I2C seems to work okay with another PIC18F running as a slave at 100KHz. This is good, although I haven't checked to make sure the rate is actually 100KHz.
However, I haven't gotten it to work with a Wii Nunchuck which runs at 400KHz, perhaps it's a pullup issue, more testing and poking at it is required.
A few questions: Should the hardware I2C module allow pullups on other hardware than the v0a? I suspect so. Was there a reason for the characters at the start of many of the messages in the HWI2C module?
I've updated the hwi2c patch to reflect the above changes. Once I'm sure that the master module is working properly, I'll write the HW I2C slave module.
Sure, I didn't specify any license because I usually just assume that the license is the same as whatever I'm patching! Sorry about that! Feel free to take any of my patches for this project under the correct license for the component I've written the patch for.
I actually got the built in functions from the bootloader code.
Cool, I've got it working. I meant C30, I've only worked with 18F PICs in the past, so sorry for the confusion. My issue was not exporting the HEX file after compiling.
Now that it's all sorted, I've got a patch to re-enable the HW I2C component: http://dev.gentoo.org/~josejx/bus_pirate/i2c.patch I haven't yet tested it since I'm still at work, but I'll get to it tonight and follow up.
Also, I see you've added code to print the revision. Instead of using the inline assembly, why not use the builtins: __builtin_tblrdl() and __builtin_tblrdh()? I think they're easier to read. Perhaps it would also be a good idea to store these values somewhere so we can check them without having to read from the flash multiple times?