I think I mentioned at the beginning of this series that I expected that porting the Arduino environment to MSP430 would be educational as well as potentially useful. So, have we learned anything interesting so far? I think so:
- From dealing with the tables set up in flash memory, the MSP430's von Neumann architecture are obviously different than the AVR's Harvard architecture. Reading a constant from flash on an AVR involves setting up particular register pairs and using a special "load program memory" instruction. On the MSP430, flash is in the same address space as all the other memory, so the table reads are just ... normal "mov" instructions. It's also nice to have a fundamental register size that matches the address space, and registers that are actually general purpose enough that any of them can be an index register.
- The regular layout of the registers controlling digital IO for each port reduces the amount of flash that needs to be used for the tables. Actually, this would probably be true on the AVR as well, but optimising for space is less important there. Food for thought, though...
- The MSP430 bit set and bit clear instructions use bitmasks rather than bit numbers. This can mean that the "single instruction" to modify a bit on an IO pin can end up being 6 bytes long! (bis.b #128, &0x0021; one word (2 bytes) for the instruction, one for the immediate bitmask argument, and one for the IO register address.) The "constant generator" allows single bits 0 through 3 to be modified using only a two-byte instruction, perhaps lending a bit of surprise to anyone expecting really tight timing.
Next up: Timers and PWM.