Close

Keyboard works, target AVR programmed

A project log for Pavapro - portable AVR programmer

Pavapro is tiny programmer you can bring anywhere. You can load binary file into it and bring/use it as you wish. And a bit more than that.

jaromirsukubajaromir.sukuba 12/28/2014 at 13:060 Comments

When doing some bigger projects - like this one - I like to build it in blocks, test each one separately and then, when everything seems to be OK, connect it together. Sometimes I use one block to test some other. So I made OLED display running and used it to debug SD card connection and FAT filesystem. Now, as I started to work on AVR ISP programming routines, I decided to connect keyboard first and make it running.The keyboard is simple 4x4 matrix keyboard, I bought it locally, though it looks like quite generic 4x4 telephone type keyboard.

It occupies all 8 IO lines of PCF8574 I2C port expander and the algorithm for reading the keyboard state is quite simple, actually and described many times before. For now, I setup the keyboard routine to read the keyboard state and return keypad number, this is enough to serve as simple user input for debugging purposes. Let's move on.

As I wrote before, the target AVR is connected and responds to simple ISP commands, giving me hope to finish the programming routines soon. Programming of AVR FLASH is done on page basis, where you must load the FLASH data into page buffer first and just then issue command to write this buffer into FLASH. The only complication is that page size is different for different AVR types (probably because of FLASH internal organization) - and because I want to support the ATtiny2313, ATtiny85 and ATmega328 at least, I have to make the page size switchable.

Page size table for ATmega88/168/328

Page size table for ATtiny25/45/85

Page size for ATtiny2313

Basically, it looks like the programmer should support at least 16-64 words (each two bytes) long pages. No big deal, but fixed size page would be nice.

To test the programming algorithm, I wrote simple software, exercised by key presses, with result fed to serial terminal. Number one started device ID check, number two read first 16 words of FLASH memory, number 3 erased the whole FLASH and key A started programming of FLASH with simple binary to blink a LED. The binary is hand-assembled and temporarily stored in arduino FLASH

sbi 0x11, 0x6 ;clear DDRD, bit 6
sbi 0x12, 0x6 ;turn LED off
cbi 0x12, 0x6 ;turn LED on
rjmp PC-0x2 ;jump up, to turn LED off

This should turn LED on and off - probably not to see with naked eye, but oscilloscope or logic analyzer should show it. The source results in this simple 8-byte machine code

stored temporarily in arduino FLASH. For now, I'm not messing with reading the binary from SD card, I'll implement this later, once the AVR ISP routines will be debugged.

Well, integration of the newly programmed keyboard routines and AVR ISP FLASH programming works fine:

Not

Notice, the FLASH is empty after first "2" command (reading FLASH), but contains the binary after "3" (erase, not needed for empty FLASH, but anyway) and "4" (load FLASH) commands. Yay!

Oh yes, and the target ATtiny2313 does what I would expect. The LED on pin 11 (PD6) looks like just dimly shines, but oscilloscope shows fast squarewave on the pin:

Because the sbi, cbi and rjmp instructions took two clock cycles (6 cycles for the complete loop) and the default clock is internal 8MHz RC oscillator, divided by 8 (resulting in 1MHz clock), I would expect something like 166,66kHz (1MHz/6) frequency. Scope shows 164kHz, what is quite nice and small deviation. The RC oscillator is temperature dependant, so I put my finger on the ATtiny2313 package for a few seconds:

Approximately 0,5% shift. Bear this in mind next time you'll be designing something with internal RC oscillator of AVR MCU.

This is progress for last night, now I'm going to clean up the ISP FLASH programming routines and link it with SD card routines to get really usable programmer. Oh, it's 28th, time to finish the contest runs like crazy and I still have a lot of work.

Discussions