20131226

F8 bug or how I hate I2C bus

I have been revisiting assembler code I wrote maybe 10 years ago because of a software bug.  The device announces the problem by displaying a message "ERROR CODE F8" which, being translated into the vernacular, means that when my Microchip 8-bit microprocessor accesses external serial EEPROM via I2C bus the bus gets into a can't-get-out-of-it situation. That the serial memory devices should suffer such ignominy is my case against I2C.  SPI bus is simpler and is my preferred choice.

It turned out I was trying to access a memory address that did not exist and, after many days of searching, it turned out that this was because I had initialised said memory (pointers and wotnot) after my first attempt to access it. The solution - move the call to the initialise code back before the first access. Simple - once I had identified the problem.

It took me so long to identify because I had very poor debug tools.  I had very poor debug tools because I hadn't previously made any those 10 years back when my teeth were shorter, and in this recent spate of work I thought I could do it without the necessary tools. This morning I decided that was bad thinking. I made a terminal routine that would dump salient registers to a display screen and hey presto I was able to locate the bug. The most helpful part of my debug tool was the display of stack pointer and return addresses on the stack from which I was able to figure what part of the code caused the error display.

Which adds weight against the inference in the absurd proverb "a bad workman blames his tools". It should read something more like "a bad workman has bad tools".

A similar principle applies when routing cables through or driving screws or hammering nails in awkward positions. If you cannot see what you are doing, chances are you will mess up: the screw will drop into a void, you will instead hit the nail on your finger, or the cable being poked will just refuse to exit where you want. But once you can see what you are up against it is oh so much easier!  For this reason I keep a stock of small flash-lights and mirrors.

There could be a moral here somewhere...

1 comment:

  1. Having been reared in Ballymore Eustace I love your posts - well not the electricity posts as I know nothing about it - about the beauty of that general area.

    ReplyDelete