Smiley Micros Butterfly C programming kit problem with portB

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, I finally got around to going through the book and butterfly kit I bought a while ago from Smiley micros. Got up to chapter 4 pages 67-68 and the PORT IO project which is connect 8 switches to PORTB and pull those pins to ground to switch the LEDs off. Problem is that something else is pulling all but bit 0 to ground slowly all the time. If I connect the PORTB pins to plus 3 volts, each LED will light and stay that way for a little while after removing the connections to the + voltage but if let sit long enough other devices on that board seem to pull the pins to ground.

Does this sound right?

Also for the life of me I could not get the computer to program through the bootloader I could get Hyper terminal to listen to the bootloader (??? appeared when I held down the button) and I could send a text name to the butterfly so it was working. But I could not get AVR Studio to see the butterfly on the serial connection. So I pulled out my armored Dragon and plugged in the ISP connection. Programs fine, but I wonder if blasting the bootloader is doing something that would prevent me from getting the proper response from PortB.

I do understand what the exercise is trying to teach me, but it is more fun if it works the correct way.

And before anyone asks, yes I did pull the ISP cable off of the butterfly and I did cycle the power to make sure.

Do I need to turn ISP off to get this to work? If so can I get in with JTAG or DW to do the programming for each step? My tools include a Dragon, an STK500, and a JTAGICE mk2. Mostly I'm using the Dragon because it has a hub (powered) built into the protective box, so I can still use my mouse and not the silly pointer on my laptop.

If I need the bootloader to make this work, can I just pull the source from somewhere and include it into each project so that I can continue to use the ISP/JTAG/DW programming?

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Do I need to turn ISP off to get this to work?
No reason to do that EVER. (those pins revert to normal I/O after programming)
Quote:
If so can I get in with JTAG or DW
The chip on the Butterfly does NOT have DW but does have JTAG AFAIK, it all depends if you want to kill the existing stuff on the board and put your in own stuff.

HOWEVER unless you REALLY know what you are doing I would advice against doing anything that drastic or you may end up with a board full of components but no functionality at all if your code does not work.

Anyway wait untill the Butterfly gurus come around to this thread for more informed advice. :-)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wanting to kill the original stuff and killing the original stuff are two different things. And the original stuff (bootloader) is now gone. I've given up for the night so waiting isn't a problem. Though I'm thinking I might just want to buy an atmega169 that will go in my STK500 and just harvest the other stuff for when I need it in the exercises.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just looked at the chip, it is an atmega169PV and I was choosing atmega169 in AVRStudio, could this be the problem?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Butterfly distribution application and the app with bootloader hex files are both available on the Atmel site. You can restore one or both with your STK500.

One of the Duh things I used to do when using the Butterfly's bootloader was forget that it needs the "AVR prog..." menu item in AVR Studio. If you're looking at Smiley's book you're probably not making this mistake.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you using external power for the Butterfly?

You can get the Butterfly Source to reload the bootloader from my downloads menu.

Did you note in the errata:
Page 68 and 70
After: DDRB = 0x00 // set port B for input
Add: PORTB = 0xFF // enable pull up on input port

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That might do the trick, didn't think of needing to pull PortB up. I'll give that a try tomorrow when I pick it back up and get going again. That might explain why at first some of the LEDs were dim.

Guess I better go get all the errata on that book and go through and add notes to the pages that need it.

And yes I did mess up between the programming routine in Studio and AVRPROG, not sure if I'll bother to put the bootloader back in if I don't need it. I'm doing everything else inside Studio, so I might as well not bother with AVRPROG.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, yes I am using the 2AA battery box that came with the kit, need to pick up a few extra batteries (had to borrow them from a TV remote).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

One thing to keep in mind is that the initial clock speed might be different if you use the supplied bootloader or ISP (e.g., with an STK500). There's a "system clock prescaler" register (CLKPR) that is used to divide the clock down, and a "divide clock by 8" fuse that by default is programmed. The fuse bit determines what the initial CLKPR value is (divide by 1 if not programmed, or divide by 8 if programmed).

With an 8MHz clock and the CKDIV8 fuse programmed, the Butterfly will start running at 1Mhz. This is standard AVR behavior. However, the bootloader does some calibration and tweaking, and among other things it changes the CLKPR register so that the Butterfly will be running at 2MHz when it starts executing your code.

If you load your program with ISP, you will start executing your program at either 1MHz or 8MHz, depending on how you program the CKDIV8 fuse.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it went to 8Mhz, I'll check the fuses when I set everything back up later today. That might explain the speed of the Cylon lights, they are a little fast even after I changed the delay to double. Maybe I'll put the bootloader back in so that it follows with the book better.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just added the errata stuff to my book, and edited the CylonEyes program. All is well now. Just too much fun!!

Wes
AE6ZM & VE7ELE
ARRL Technical Specialist
Lincoln, CA
Placer ARES

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yup the pull up worked properly and I'm back on the path, thanks. Up to chapter 5.