Sunday, January 30, 2011

LPC1751 & I2C & SPI

Today I finally got the I2C working together with the ITG-3200 chip. It took me two days! That's right, two!
First I tried to write the hardware parts completely by myself with the data-sheet. This succeeded more or less. I managed to read data from the gyro but it wasn't interrupt based and it didn't worked stable. It was also weird for me to work with one same register that is separated in a REG_CLR and REG_SET to change bits.
Also the order wasn't really clear for me from the datasheet, maybe it is because I like the way datasheets from microchip are written: a small C demo and 123 steps how to send/read/init data...Yes there was also something like 123 in the NXP sheet, but no code examples. And on top of that, the used i2c bus from the ARM chip (I2C2) wasn't listed in LPCXpresso, huh?? Still not sure if it's an error in LPCXpresso, I already posted an topic about it on Red Suite.

Anyway, I searched the demo folder from Red Suite site for an example. Fortunately there was a interrupt based i2c written. I adapted it to my chip and retried the same story. Again, I failed to get the registers out of the gyro. With my oscilloscope I (double) checked the start bit, address byte, etc, etc... but I didn't found any problems at all! After almost 2 hours searching and debugging I found out that the ITG-3200 doest reply anymore if you have written some weird commando's to the chip. Powering off (and discharging it's capacitors off course) did the trick.
Now I finally managed to read out the 16bit X data... great :D.

Oh, and I already succeeded with the accelerometer a week ago, that was a peace of cake fortunately :D. Next thing to do is to read out both sensors on external interrupt trigger base to maximize the speed and minimize the polling. And then the filtering part, and than matlab... ouch... still enough to do....