Miksu
Miksu

Reputation: 143

Programming Atmel ATMega 32-16pu using Raspberry PI

Some time ago, I bought the ATMega32-16PU and I thought, I could program it with Raspberry PI's GPIO pins. I tried it several times and I realized that ATMega32-16pu needs 5v and 5v could break my Raspberry PI so I bought schmitt trigger to shift the voltages of the signals that are going back to the PI. Now I'm thinking, if it's even possible to program the ATMega with Raspberry.. If it isn't, what kind of programmer should I buy?

Upvotes: 0

Views: 864

Answers (1)

vlad_tepesch
vlad_tepesch

Reputation: 6891

AVRs usually also work on 3.3V with maybe reduced max allowed clock frequencies (the older ones can go down to 2.7V, the newer ones even to 1.8V), so you directly can use your Raspis SPI to program them - without any level shifters.

You also may use newer AVRs (e.g. the mostly compatible AtMega324 - you also can easily scale up or down on flash/memory size). So you can set the fuse to ckdiv8 so it is active while programming (being 3.3V capable at this time) and remove the clock divider at startup in your program, if you require the maximum clock frequency.

If you are tied to the old Mega16 then at least you need no level shifter for the inputs, since the AVRs threshold for 'high' is 0.6*VCC. Except for the Reset Pin, but chances are good that this works anyway. So only the MISO Pin does need some care. A Simple voltage divider should be enough AVR) --[ 10k ]-- (RPI) --[ 20k ]-- (GND

It also seems that you can use avrdude with the programmer linuxspi. Please refer documentation.

This Article of a german micro controller community website advises the adaption of the config files to set the correct pin that is used to reset the AVR and suggests the adaption of the baud rate in the config file.

programmer 
  id       = "linuxspi";
  desc     = "Use Linux SPI device in /dev/spidev*";
  type     = "linuxspi";
  reset    = 25; # <- your reset pin
  baudrate = 100000;
;

The avrdude command line to read the flash content to /dev/null for a connection test then looks somehow like:

sudo /usr/local/bin/avrdude -c linuxspi -p m32p -P /dev/spidev0.0 -U flash:r:"/dev/null":r

Upvotes: 1

Related Questions