EsotericAlgorithm's Blog

Random Hobbies and Whims

Posts Tagged ‘c

Eclipse and the AVR Toolchain

leave a comment »

Success. I have finally figured out how to program an AVR chip using the toolchain and an iscp. The first issue that I was having was a permissions issue as the device was not given access permission so I had to sudo every command. Not a problem initially but it became a problem once I began using Eclipse. In order to solve the problem I stayed up late hacking away. I pinpointed it down to needing to set a rule for udev. Eventually I solved the problem. Out of curiosity I searched for my problem with the same search I had done at the start only to find a very complete tutorial.

The second issue was in compiling the AVR toolchain due to some dependency hell I ran into with the boost library. Long story short. gnu-avr-toolchain is a package in the repo. Next time I will search the apt-cache like a sane user. After finishing this I had two choices, produce or copy a make file to build an uploadable hex or find an IDE that could do it for me. My experience with most IDEs thus far has been pretty terrible but I figured I would give Eclipse another shot due to the excellent AVR plug-in available along with vi key-bindings accessible through the vrapper plug-in.From there it was simply making a couple configuration changes and uploading the hex file automagically.

Although the above is fairly condensed as I have been working on this for the past couple days. I’ve stopped using the book on C I mentioned a while back primarily as I can try and code something more applicable to my situation and learn through doing.

Finally, I’ve been using my Boarduino as a programming board which has worked wonderfully, but unfortunately the pins don’t line up the m328p schematic so I’ve often misplaced a pin and had to test it a couple times. This is very useful especially in its explanation of ports. I’m unsure on why part of that code points to pin 6 as 0x20 is 00010000 which I thought would specify the 5th pin. Some more reading should solve the issue. The Vin pin on the Boarduino is regulated. AWESOME! that saves me from buying a 7805 for a while at least. The clock is off I need to fiddle with the fuse bits.
Covered in mosquito bites.

Written by esotericalgorithm

July 8, 2010 at 2:32 pm

AVRdude Trials and Tribulations

leave a comment »

I stabbed myself with my soldering iron on max heat. I intended to update yesterday with how my foray into AVR programming has progressed but ended up going on a last minute trip to Wilipa Bay for snail research. Anyways after a rather long soldering sessions I finally got my Boarduino and usbtinyisp put together. After some search for a USB to USB -B cable with no luck I cannibalized one off a printer to test them. The isp lit up as did the Boarduino when powered via the DC jack (and via the 5V pin while in a breadboard).

Tinyusbisp on the left, Boarduino on the right

The next set of steps followed naturally: program the Boarduino with a test application allowing for testing and to establish the processes needed to upload programs. Using an FTDI cable or a usb breakout board the process is relatively trivial and is very much plug and play. I purchased an icsp instead of an FTDI cable as I planned to program using straight avr code (C/asm) fairly quickly as the Arduino is somewhat limited in those capabilities (except it can use all of the tools such as more precise timers, but I figured switching from one to the other would be as shocking as switching from a dynamic to a static language). My main source of information was this article found on the Arduino website. I made the necessary edits and assumed I would be on my way to programming bliss in a couple minutes. I tried to upload a simpleĀ  blink sketch via the Arduino IDE which resulted in an error:

java.lang.NullPointerException
	at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:67)
	at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:53)
	at processing.app.Sketch.upload(Sketch.java:1460)
	at processing.app.Sketch.exportApplet(Sketch.java:1427)
	at processing.app.Sketch.exportApplet(Sketch.java:1382)
	at processing.app.Editor$45.run(Editor.java:2165)
	at java.lang.Thread.run(Thread.java:637)

Sadness.

I fiddled with that for quite a while and tried various ideas that might have been the problem to no avail. Defeated I decided I would try to communicate with it via avrdude. Yep that worked fine, I even got confirmation that both devices were functioning correctly. Alright.

I open up the Arduino IDE one more time and use the burn bootloader option using tinyusbisp; that would assuredly confirm functionality as well. It starts and lasts a couple minutes, the red LEDs on both devices are lighting up, it’s programming! It finishes and the red LED on the Boarduino continues to blink…

Strange that isn’t in the uploaded bootloader. I load up avrdude and erase the bootloader, it stops blinking and the reset button no longer causes a response, perfect! SO I reup the bootloader and it starts blinking again. Ug. After looking into the issue it appears it may be related to corruption during the upload process.

I haven’t found a solution yet as I haven’t been able to set aside any time for it (about to!) but generally it looks like I will approach the situation using just avrdude. First I need to setup the avr-toolchain (small quirk) and possibly add in the Wiring libraries so I can take advantage of the Arduino libraries if possible.

As for my goals in my previous post I accomplished all of them! My understanding of bitwise operations/functions is still superficial but I intended to implement them into a project in the near future. Tonight I shall assault strings in C. The task shouldn’t be too difficult as I alright have a decent amount of prior knowledge of the topic.

On an unrelated note, I have to move in the next month I found out yesterday. That sucks.

Written by esotericalgorithm

July 2, 2010 at 8:22 pm

The Beginning of the Beginning

leave a comment »

I’ve recently ventured into low-level programming in C (I’m sorry to the assemblers who cut their teeth on calling C low-level) before this I used Python. For reference I’m using several books the most useful Sam’s Teach Yourseld C in 21 Days. I perused several books including the Holy K&R, which although information rich, was too terse for self-study and lacking the exercises I needed to direct me. In terms of content it explains in 20 pages what K&R does in 3, slower but more through but even that doesn’t lead to some confusion.

My biggest qualm is that all of the books I’ve looked at address pointers before they address variable scope. Not much of a problem I though initially but without addressing proper initialization it leads to frustrating errors such as

#include <stdio.h>
// Declare a variable and a pointer to that variable

int not_a_pointer, *not_a_pointer_ptr;
not_a_pointer = 4;
not_a_pointer_ptr = &not_a_pointer;

int main(void) {
     DoSomething();
     return 0;
}

which ultimately returns a compiler error because it was initialized in the global scope (or at least that’s my understanding at the moment).

A second bit of trouble that I am having but hopefully I’ll figure out in the coming hour is passing arrays through a function. I understand array pointer declaration and pointer incrementing, although I’ve had some complaints about improper cast type for a pointer when both the pointer at the memory address were to integer casts. Casting it also resulted in a failure. Hopefully tomorrow I’ll discover a solution. Although if my Atmel AVR order from Elexp arrives tomorrow I’ll be throughly distracted.

Goals for Tomorrow

  • Throughly understand pointer
  • Write some functions to pass pointers
  • Start and finish bitwise functions
  • If supplies come solder together usbtinyisp

Written by esotericalgorithm

June 30, 2010 at 3:17 am