Thursday, September 25, 2008

SPI success!

I've had no luck getting the atmega168 to talk to a DS1307 RTC chip over i2c. My colleague Greg suggested using an RTC which uses SPI. After getting my hands on a couple DS1305s, I wired it up, and wrote some code to bit-bang SPI using several pins on port C. (I didn't use the hardware SPI support because those pins are used for in-system programming.) I tried it out, and---nothing. Every register read would return 0, which seemed a bit odd.

Eventually, I replaced the DS1305 with some LEDs, and wired the atmega168 pin I was using for input from the DS1305 to +5V, and noticed that even though the LEDs were blinking correctly (I slowed the SPI protocol way down), I was still getting 0 when I did the read.

Long story short, AVRs have different registers for reading and writing ports. For example, PORTC means "write to port C", while PINC means "read from port C". I, of course, was trying to read from the output register. Fixed the code, and presto, my test program worked. All it does is repeatedly writes an incrementing counter to one of the DS1305 RAM addresses, and reads it back.

The obligatory picture:

The DS1305 is the chip just to the right of the atmega168.

Next step: use a MAX7219 to drive the 7-segment displays.

Thoughts on the bailout of the financial industry

Spending $700 billion to bail out the financial industry is about $2300 per US citizen.

So, the US government wants to spend $2300 of my money (probably more) to clean up the financial mess left by greedy and stupid people. We're letting the people who knowingly arranged and sold bad mortgages off the hook. We're also (presumably) letting the people who knowingly walked into mortgages they couldn't afford off the hook.

I now feel really stupid for working an honest job and living within my means. Our government seems to be largely in the business of making sure that the unscrupulous prosper.

Friday, September 12, 2008

ATMega168, i2c/twi

I changed by AVR circuit to use an atmega168 rather than the attiny2313. The primary reason is that I'm trying to use the i2c code from the Procyon AVRLib in order to talk to a DS1307 real time clock, and avr-libc doesn't seem to have the required register definitions for the attiny2313. I don't know why - the attiny2313 is supposed to support hardware TWI (really i2c).

Here's a snapshot of the new circuit, taken again with the world's worst digital camera:

My program successfully loads and runs on the atmega168. Next step: actually try to talk to the DS1307.

Tuesday, September 9, 2008

Powered by Ubuntu sticker

When I got my new Thinkpad X61 tablet, I (naturally) removed the "Designed for Vista" sticker and threw it away. That got me wondering whether anyone has made a "Designed for Linux" sticker. And of course, the answer is yes, and they're free:
Double w00t!

The sticker actually says "Powered by Ubuntu", but that's good enough for me.

Getting Eclipse to work on 64-bit Linux

Back at the beginning of the summer, I was experiencing strange Eclipse crashes after an upgrade to 64-bit Ubuntu. My solution at the time was to switch over to Netbeans, which worked out very nicely.

Since students here at YCP are using Eclipse for Java development, I thought I'd take another stab at getting things working.

As it turns out, there is an easy solution: use the IBM JDK. Instructions are in a comment in the following blog post:
Basically, you grab the RPM for the IBM JDK, use alien to install it, then use the -vm Eclipse switch to launch it using the IBM JVM.


Since the problem seems to be in the Sun JVM, and not Eclipse, I have to wonder why Sun has let this bug linger for such a long time.

Friday, September 5, 2008

Improved Blinkenlights

My AVR-fu is slowly improving.

I'm now using the AVR-PG1B programming cable I ordered from SparkFun, along with a DB9 cable and a breakout board that adapts the 10-pin AVR ISP header to a single-row 6 pin header, which then plugs into my breadboard with a cable and gender changer from Digilent. Very nice, works like a champ. (Note: avrdude calls this programmer "ponyser".)

I constructed a circuit interfacing the attiny2313 with an ICM7212 7-segment LED driver. So far, I only have 2 of the 4 supported digits wired, but it works nicely. Here's a photo (taken again with a very crappy camera) of the whole mess:

There's still plenty of room on the breadboard for another IC and a few switches, which are needed for my crazy top-secret project.

Tuesday, September 2, 2008

Blinkenlights success!

I couldn't wait for my AVR programming cable to arrive from Sparkfun, so I decided to build a parallel cable.

Long story short: it works. I used the pinout suggested by, which in avrdude is the "bsd" programming device. Although that site suggested 1K resistors in series with the signals from the parallel port (to protect it from current flow from the AVR circuit), I couldn't get the device to program successfully with them in place. So, I just used wires :-)

For the cable, I soldered 5 wires of an 8-wire ribbon cable to the DB25 connector, and crimped a 16-pin socket-style connector onto the other end. I don't know exactly what those connectors are called, but they're designed to fit into an IC socket. That makes them nice for breadboards, which can't really accept dual row (IDC) headers directly.

For the program, I used the code from Elliot Williams's excellent (no, inspiring) piece on cheap AVR programming. I didn't build his development board/programming cradle (did I mention that I hate soldering?), but I used the same circuit.

Here's an amazingly crappy digital photo of the circuit and the programming cable:

Dave Babcock and Greg Link helped me put the whole thing together. It's really nice working with actual engineers :-)