Wednesday, January 30, 2013

Multiple chip communication and Code documentation

Well once again I've ended up on a forced hiatus. This time its because we're re-roofing part of our house and its taking far longer than thought plus I've ended up with lots of work clumped together so no time to relax in-between. This should finish next week sometime as I'm working constantly until Friday night and then I think I'll be back on the roof again, at least I've ended up with a good tan from it.

Anyway my next goal is to set up SPI communication between two microcontrollers (I just realised I should try three controllers very soon after). In my last post I said I was having trouble with the chip not functioning properly without the programmer attached. I've now fixed that with a 1uF capacitor. What took me so long was that I was unsure about the size as I had previously had a capacitor that was much too big and so didn't do any help. I had a look round and the Atmel documentation seemed to indicate some thing in the range of micro farads but the capacitor used on the Audrino Uno was a 100nF capacitor. As I didn't have any capacitors that size at home I tried a 1uF and it works fine (as in everything functions properly without the programmer attached) so I'll keep that for the time being.

So what I'm aiming for with my test SPI setup is to have a microcontroller with some buttons attached which then communicates to another microcontroller which then drives the stepper motor. In the setup with two microcontrollers, the microcontroller attached to the stepper will then reply with the success or failure as well as some properties of what it did such as how many steps from its original location etc.
I haven't thought about what I will do with the three microcontroller setup as I have only just thought of the idea while writing this post.

There is one problem with SPI other than those mentioned previously (I had a post ages ago when I talked about it) and that is that it is also used to program the device. So to overcome this I'm going to but some detect switches (that is at least what that are called on element14) and connect to some transistors to break the SPI connection when the programmer is plugged in. I won't have this on the final product just for use on the breadboard as the final product should be able to have the SPI disconnected more easily via a cable or similar.

So that is my next step for the electronics side of things. I'm very pleased with how things are going along at the moment other than having to spend so much time not working on the project!

With code, I keep saying I'm going to comment it and make it more readable. I've decided I'm going to use Doxygen for inline commenting and documentation. This is so I use a standard format for commenting but also so I can learn how doxygen works for other programming projects I work on. I've read some basic info online and I've now ordered a book. This is mainly as its easier to have a book to reference than going online all the time and all the information will be in one place. On a side note I've also bought a book on Autotools which means once I get most of the different electrical parts working, I can have the code of the main controller all auto configured and have options when compiling, such as methods of communications for getting the 3D data files to the controller (eg: SD card, USB and ethernet).

Just some quick other things, I'm going to see if I can setup SVN under AVR Studio as this would be a good way of keeping track of revisions of code plus I can use it to sync with code that I've written under OSX. The other thing I wanted to mention was that in the code in the last post, I should have also turned off the start up message on the LCD as when you first turn it on, it doesn't format the text passed too it correctly. The last thing is that I start uni again in just under four weeks so I'll be able to spend more time then thinking about the project.