3 hours ago
If the type is too small, Ctrl+ is your friend
Wednesday, February 17, 2010
After almost a week of fussing, I finally got to the point where I could control the LED's on this project. You might think I exaggerate the difficulties, but I assure you I do not. You see, these little lights are not controlled directly by lines to the CPU, but by another chip, an intermediary. This intermediary is not what you would call civilized, growing up as it did amongst hard nosed gates and latches. It is a child of the hardware world and never learned any of the protocols of civilized discourse. The only language it speaks is that of clock and data. In short, it uses the I2C interface, an uncouth manner of communication somewhat analogous trying to talk to the king of a Byzantine empire using Morse code.
I2C stands for Inter Integrated Circuit. It is a serial communications protocol used for transferring data between chips on the same circuit board. It was invented by Philips, which gives me one more reason to hate Philips.
I had numerous examples to study, and one piece of code written specifically for this board. After numerous trials I got this last program to turn on all the LED's for one brief moment. I never got it to work again. If it hadn't been for that one shining (!) moment I would have been ready to toss in the towel. I waded through the instructions, and tried to write some code that followed the directions, but there are layers and layers. The worst part is I do not know exactly what I did at the end that finally made it work. So far it seems repeatable, but I am keeping my fingers crossed.
One thing that struck me is the use of mnemonics for some things and numbers for others. Writing code for this project involves addressing registers. The processor has 100's of registers, each of which has a name, like I2C2CON which stands for I2C (2nd Module) control register. Each of the bits in this register likewise has a name. The manufacturer has conveniently provided a file which has all the names of the registers defined, as well as providing mnemonics for all the bits in all the registers as well. For some reason, the register names do not seem too bad, but the names for the bits within the registers are too clumsy to use easily. Things like I2C2STAT_BCL_MASK are just more trouble than they are worth. It is much easier to just say BIT10, also slightly more reliable.
For this project I had to deal with each register often enough that I learned it's name. I never bothered to learn it's address. I might not deal with all of the bits in that register, and I might only deal with any particular bit only once. To use the bit, I read the reference manual that describes the function of the register. It's position within the register, along with the register's name is documented in the manual. However the mnemonic assigned to the bit is in another manual, or in a header file. So using the mnemonic requires an additional step to find out what it is. Well, that explains why I didn't use the mnemonics for the bits within the register, but I did use the names of the registers themselves. Huh.