Some HELP with programming an Atmega32U4 with ISP

Arduino-related hardware discussion (including Teensy and other Arduino clones)
User avatar
Helder
Trailblazer
Trailblazer
Posts: 2237
Joined: Thu May 05, 2016 8:33 am
Location: Fall River, MA
Has thanked: 1161 times
Been thanked: 2799 times

Some HELP with programming an Atmega32U4 with ISP

Post by Helder » Fri Jun 24, 2016 6:02 pm

Sooooo I'm at my wits end right now trying to program my test board with the bootloader and eve skipping that and using a compiled hex of the controller code and no matter wtf I do it always give me a verify error at the end about data mismatch.

I had to use my leonardo as an ISP Programmer to reprogram my USB programmer as a USBasp which it did and both the Leonardo and USBasp give me the same error. Then I also have no idea on the fuses and have tried many many combinations using the fuse calculators and default setting and even the bootloader fuse setting in a tutorial :

http://electronut.in/bootloader-atmega32u4/

Still same error and when I plug it in the USB into my PC nothing is recognized like nothing is plugged in, I checked the fuse and the chip itself which is getting the 5v and the chip is recognized in the programmers with the ISP header.

Any help on this? I'm about to solder up another board and throw this thing out the window and see if the new one will have better results.
My Sale Threads:

Retro PSU, 3.5A output!


Chat with me and other members


Don't contact me about obtaining my board files (as you will not get them). Don't contact me about any of my boards if they are sold out, they will be restocked as soon as I can get them.


Don't support thieves like ckliang who copied my AIO to resell and is now cloning the mintyPi, support the original creators and not the thieves!

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Fri Jun 24, 2016 8:20 pm

I was going to work in a simple solution that you can use the raspberry zero to program the atmega chip but not until Monday.

You can get an idea for what I'm talking about here:

https://learn.adafruit.com/program-an-a ... -gpio-pins

Be careful with the fuses... if you set wrong fuses it might not be able to use the ISP to program it with ANY programmer!


Thanks
Thanos

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2237
Joined: Thu May 05, 2016 8:33 am
Location: Fall River, MA
Has thanked: 1161 times
Been thanked: 2799 times

Re: Some HELP with programming an Atmega32U4 with ISP

Post by Helder » Sat Jun 25, 2016 11:42 am

That would be good for people who get the boards blank but I need to test mine to be sure it's all good (your testing will be helpful too).

Here is the link to the code for the controller:
https://github.com/oxodao/GBZGamePad

Also has the link to the one I linked in the first post.

Could you give me the settings especially the fuses and the bootloader hex files to properly program the 32u4? I don't want to use the Pi since I have 2 programmers that I'd rather use anyways.

Maybe provide me the hex with bootloader and controller programmed into it already, I'm also using AVRDudess for the programming which is just a AVRDude Gui.
My Sale Threads:

Retro PSU, 3.5A output!


Chat with me and other members


Don't contact me about obtaining my board files (as you will not get them). Don't contact me about any of my boards if they are sold out, they will be restocked as soon as I can get them.


Don't support thieves like ckliang who copied my AIO to resell and is now cloning the mintyPi, support the original creators and not the thieves!

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Sun Jun 26, 2016 10:21 am

Do you have any programmer compatible with AVRStudio4 ? That is the best way to ensure you flash the correct fuses.

Also make sure the crystal has correct orientation.

BTW, what is the model of crystal you used? The ones I use are two pin and much smaller.

I haven't got to the bootloader yet as I don't have an ATmega32u4 mounted on a board yet, I was waiting your board. But I also ordered a dev board for it in case there is a design error on your board preventing the ISP from working correctly. Can you pm me a schematic of the board to ensure all is connected correctly?

Thanks
Thanos

User avatar
Helder
Trailblazer
Trailblazer
Posts: 2237
Joined: Thu May 05, 2016 8:33 am
Location: Fall River, MA
Has thanked: 1161 times
Been thanked: 2799 times

Re: Some HELP with programming an Atmega32U4 with ISP

Post by Helder » Sun Jun 26, 2016 11:24 pm

Yea I'll get you the info you need when I get home.
My Sale Threads:

Retro PSU, 3.5A output!


Chat with me and other members


Don't contact me about obtaining my board files (as you will not get them). Don't contact me about any of my boards if they are sold out, they will be restocked as soon as I can get them.


Don't support thieves like ckliang who copied my AIO to resell and is now cloning the mintyPi, support the original creators and not the thieves!

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Tue Jun 28, 2016 3:26 pm

Just to let everybody, I got it working.

Tomorrow, I'll backup the bootloader+program to a hex file, along instructions to flash it using AVRDUDE on Raspberry command line, as its the easiest way right now for people that do not have hardware programmer (AVRMKII).


Thanks
Thanos

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Tue Jun 28, 2016 7:07 pm

Hey Helder,

Here are few photos for now of the board with the new crystal:
IMG_20160628_171120.jpg
Modified ceramic crystal
IMG_20160628_171120.jpg (520.67 KiB) Viewed 4392 times
IMG_20160628_171057.jpg
Attached to the programmer
IMG_20160628_171057.jpg (539.24 KiB) Viewed 4392 times
Thanks
Thanos

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Wed Jun 29, 2016 7:01 am

Hi Helder,

The Crystal I used is a Ceramic one:
http://www.digikey.com/product-detail/e ... -ND/584635

I placed a 1Mohm resistor in parallel with the crystal to filter any noise. No extra capacitors required.
I also didn't use the Fuse you have on the parts list, I just shorted it out with a piece of wire.

I soldered a 6-pin connector so I can use the ribbon from my Mattair Zeptoprog II programmer.
https://www.mattairtech.com/index.php/zeptoprog-ii.html

I used the Atmel Studio 4 to program the Atmega32U4.
IMG_20160628_204134.jpg
Avrstudio4 connected to the device
IMG_20160628_204134.jpg (707.84 KiB) Viewed 4376 times
Fuse should be as:
Extended fuse: 0xCB
High fuse: 0xD8
Low fuse: 0xFF
IMG_20160628_204051.jpg
Fuses for Atmega32U4
IMG_20160628_204051.jpg (729.35 KiB) Viewed 4376 times

I used the Bootloader file from here:
https://github.com/sparkfun/Arduino_Boa ... icro16.hex

IMG_20160628_204247.jpg
Loading the Caterina Bootloader
IMG_20160628_204247.jpg (758.46 KiB) Viewed 4376 times

The equivalent command IF using AVRDUDE would be:

Code: Select all

avrdude -p m32u4 -P usb -c avrispmkii -U flash:w:Caterina-promicro16.hex -U efuse:w:0xcb:m -U hfuse:w:0xd8:m -U lfuse:w:0xff:m

Now you Should see the COM port appear when you connect the USB to the computer. Mine shows as Teensy board as it using their driver, but in Arduino Ide you still select the Sparkfun Pro Micro 5v /16Mhz.
IMG_20160628_204401.jpg
The board enumerates as COM port
IMG_20160628_204401.jpg (580.52 KiB) Viewed 4376 times
Before you be able to load the code you should make sure you have Arduino Ide 1.6.6 and Arduino AVR Boards 1.6.9 loaded.
IMG_20160628_204727.jpg
Making sure I have loaded arduino AVR boards 1.6.9
IMG_20160628_204727.jpg (579.67 KiB) Viewed 4376 times
Then add the Repository for the Description of Sparkfun AVR boards found in this link (instructions included):
https://github.com/sparkfun/Arduino_Boards
IMG_20160628_204754.jpg
Adding Sparkfun AVR boards in Arduino 1.6.6
IMG_20160628_204754.jpg (604.76 KiB) Viewed 4376 times
Select the correct board from Arduino Ide:
IMG_20160628_204455.jpg
Select the correct device in Arduino Ide
IMG_20160628_204455.jpg (577.54 KiB) Viewed 4376 times
Load the GameBoy code:
https://github.com/oxodao/GBZGamePad

and FIX the Missing PULLUP part (it has to be "<14"):
IMG_20160628_204649.jpg
Fix the x<14;
IMG_20160628_204649.jpg (483.87 KiB) Viewed 4376 times


Upload the arduino code to the board and Enjoy!
IMG_20160628_204605.jpg
Game controller!!!
IMG_20160628_204605.jpg (512.44 KiB) Viewed 4376 times



Thanks
Thanos

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Wed Jun 29, 2016 9:24 am

I just realized the Up - Down buttons are also inversed.

See below correct code:

Code: Select all

#include <Gamepad.h>
Gamepad gb;

#define BTN_DOWN 1
#define BTN_UP 0
#define BTN_LEFT 2
#define BTN_RIGHT 3
#define BTN_A 4
#define BTN_START 5
#define BTN_Y 6
#define BTN_L1 7
#define BTN_X 8
#define BTN_R1 9
#define BTN_R2 10
#define BTN_L2 11
#define BTN_B 12
#define BTN_SELECT 13

void setup() {
  for (int x = 0; x<14; x++){
      pinMode(x, INPUT_PULLUP);
  }
}

void loop() {

  bool downSet  = digitalRead(BTN_DOWN);
  bool upSet    = digitalRead(BTN_UP); // No pun intended
  bool leftSet  = digitalRead(BTN_LEFT);
  bool rightSet = digitalRead(BTN_RIGHT);
 
  gb.setLeftXaxis(!leftSet ? -127 : !rightSet ? 127 : 0);
  gb.setLeftYaxis(!downSet ? 127 : !upSet ? -127 : 0);

  gb.setButtonState(1, !digitalRead(BTN_A));
  gb.setButtonState(2, !digitalRead(BTN_B));
  gb.setButtonState(3, !digitalRead(BTN_X));
  gb.setButtonState(4, !digitalRead(BTN_Y));
  gb.setButtonState(5, !digitalRead(BTN_SELECT));
  gb.setButtonState(6, !digitalRead(BTN_START));
  gb.setButtonState(7, !digitalRead(BTN_L1));
  gb.setButtonState(8, !digitalRead(BTN_R1));
  gb.setButtonState(9, !digitalRead(BTN_L2));
  gb.setButtonState(10, !digitalRead(BTN_R2));

  gb.sendUpdate();
}

User avatar
tronicgr
Posts: 144
Joined: Tue Jun 07, 2016 4:26 pm
Has thanked: 112 times
Been thanked: 67 times
Contact:

Re: Some HELP with programming an Atmega32U4 with ISP

Post by tronicgr » Wed Jun 29, 2016 10:02 am

Now, if you want to do all the above much easier, you can use the Raspberry as programmer!!

Here are some basic instructions:

SSH to the Raspberry and install avrdude

Code: Select all

sudo apt-get install avrdude
Verify installation by running the command

Code: Select all

avrdude -v
Copy the configuration file to the home directory

Code: Select all

cp /etc/avrdude.conf ~/avrdude_gpio.conf
Edit the configuration file to add new programmer info and assign the GPIO we want to use

Code: Select all

nano ~/avrdude_gpio.conf
ADD These lines

Code: Select all

# Linux GPIO configuration for avrdude.
# Change the lines below to the GPIO pins connected to the AVR.
programmer
  id    = "pi_0";
  desc  = "Use the Linux sysfs interface to bitbang GPIO lines";
  type  = "linuxgpio";
  reset = 26;
  sck   = 16;
  mosi  = 20;
  miso  = 21;
;

To program an AVR from the Pi you'll need to have 4 GPIO pins free on the Raspberry Pi. These pins will connect to the AVR's ISP/ICSP MOSI, MISO, SCK, and RESET pins.

In addition you'll connect the Pi's 5 volt power and ground to the AVR to power it during programming.

From the GPIO we used in the configuration above you need to connect the following:

Gameboy board <--> Pi Zero GPIO
Vcc = 5v
Gnd = GND
reset = 26
sck = 16
mosi = 20
miso = 21
ISP_pins_gamepad.JPG
ISP inputs on Gameboy pad PCB
ISP_pins_gamepad.JPG (97.38 KiB) Viewed 4354 times

Download and copy the following hex file in home directory of raspberry pi zero (Unzip first).
Bootflash_program_gameboy.zip
ATMega32U4 bootloader + Gameboy program
(16.43 KiB) Downloaded 69 times
To program the bootloader and the program into the new (empty Atmega32U4 chip), execute the following command:

Code: Select all

sudo avrdude -p m32u4 -C ~/avrdude_gpio.conf -c pi_0 -v -U flash:w:/home/pi/Bootflash_program_gameboy.hex:i -U efuse:w:0xcb:m -U hfuse:w:0xd8:m -U lfuse:w:0xff:m

That's it, now the Atmega32U4 is ready to be used as gamepad, and also contains a bootloader that can be used to be reprogrammed via Arduino IDE if any changes in the code are needed.



Thanks
Thanos

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest