basic atmega328 breadboard

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

Hi all, i have been attempting to make a breadboard with an atmega328p chip and upload the blink sketch to it, all have thrown some sort of failure, I have attempted multiple ways to get around it, with no success!. they are generally like:-

 

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xf0

 

but also have 0X00, 0X20, 0X10, 0Xff, 

 

I am using the cp2102, i have checked the wires, got a 2nd chip(same errors), installed port driver(arduino sees it as "port 3"), and have searched lots for an answer with no avail!, when i plug the reset of the cp2102 into the reset of the atmega it throws:-

 

avrdude: ser_drain(): read error: The I/O operation has been aborted because of either a thread exit or an application request.

 

 it seems that no one knows what to do!

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

 

 "it seems that no one knows what to do!" - why do you say that? You've probably got a number of problems all conspiring to have your device not work. Arduino was developed to make things easier, but some people just want to do it the hard way.

 

Your mega328 - does it have the Arduino bootloader loaded, fuses set correctly and a 16MHz crystal and associated circuitry connected? How have you confirmed all of this?

Have you wired the chip and the serial interface correctly?

Have you used the Soundcard oscilloscope to check serial activity?

 

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

Did you put by pass (100 nF) capacitors?

Have you got a phone, to take some photos (sometimes, one does not see obvious mistakes and other people see them very fast)?

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

"blink sketch" suggests you also have a "real" Arduino perhaps? if so why not just use it as an ISP programmer for the standalone 328 and forget trying to use a bootloader with it?

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

clawson wrote:

"blink sketch" suggests you also have a "real" Arduino perhaps? if so why not just use it as an ISP programmer for the standalone 328 and forget trying to use a bootloader with it?

 

I quit using the bootloader because I found it set an output pin high on power up. The Arduino IDE generates a hex file and I just used a USBTinyISP to directly program the hex file to the 328, worked great then. I just used an Uno board and plugged the 328 chip into that for programming, using the 6 pin ISP header to connect to the USBTinyISP.

 

But that was some time ago and now I'm mainly doing AVR-GCC with Atmel Studio and an Atmel-ICE. Still use an Uno board to program the chip though.

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

Programming a uC on a breadboard is fine, you just need to get all of the necessary connections made, and make sure your programming interface is correct.

 

Have you drawn a schematic of your micro and the connections you need to make?

You should do so if you haven't done so already.

Then post the schematic diagram here so others can check it.

 

Also, as mentioned above, post a good photo of your setup.

 

JC

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

BTW, you do know that on many breadboards the power rails are NOT connected in the middle of the breadboard, and you need to jumper them.

 

That's the little brown wires on this breadboard, shown below.

 

JC

 

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

At first the breadboard power lines broken in the middle tripped me up but i worked that out a week ago, Yes, the atmega is labeled to have a boot loader, and came with a crystal, this is the 2nd chip i bought and with the same upload issues, from a basic layout i built a basic circuit, and got the s$%ts with playing with leds on pins so built a test led circuit as per the image, "Soundcard oscilloscope to check serial activity?" is what-where-how-when?. So in general size/efficiency what is the difference between a atmel studio sketch and an arduino sketch?

 

I have searched and found several pages with people having similar problems, many of which the people don't report solving the problem, thus they must have given up!, how can this be so!, programming a chip isn't as difficult as landing a spaceship on the moon is it?. Also, the weird avr dude keeps spitting random 0X-- stuff at me and i could not find a reference to any meaning for it!

 

Attachment(s): 

Last Edited: Tue. May 24, 2016 - 01:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Once you program the chip using ISP, it no longer has the bootloader code on it, but you can reprogram it using the usbasp or the uno as programmer and the arduino IDE!

 

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

As far as i know it is a SPI connection simular to this,

Attachment(s): 

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

I would think TX > RX and RX > TX!

 

 

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

 "Soundcard oscilloscope to check serial activity?"

Have a look at https://www.zeitnitz.eu/scope_en

(it goes up to 44ks/s -> you can see a 4800/9600(distorded) signal

It is very cheap (no extra hardware, everything is already in your PC); however, if signals are too high, it might break yourPCs sound card)

 

I had a look at your broad beard; two things worried me (though the Tx->Rx issue ki0bk hinted is a mistake I always do) :

your avr should get supply from both sides,

with decoupling -100 n- capacitors -see Doc JC's broad beard.

 

 

 

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

I tried multiple ways with both just upload, and resetting the chip upon compile, the ways were with the way it was Rx-RX and TX-Tx it threw an error code:- sync: resp=0xb6 I unpluged the TX(chip) and plugged the RX-TX and a green light came on on the CP2102, but it threw:-  sync: resp=0x3f I then plugged the TX-RX (the green light went off) and got:- sync: resp=0xa3

all times it seemed to wait about a minute after compile before throwing an error!

when i cut the power to the chip while attempting upload i got:- sync: resp=0xe2

after power up i get:-sync: resp=0xec

but why would the green light come on when only one cable connected, and is the uart suppose to flash a light when working?

 

so the sound card thing is basicly hook the uart up to a sound cable and watch the sound monitor on my computer for the uart signal?

 

i grounded the reset with both rx-tx cables plugged in and got an immediate drop out response, meaning there is some communication going on!

 

thanks

Last Edited: Tue. May 24, 2016 - 03:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A couple of thoughts:

 

As dbrion mentioned, you need By-Pass caps.

Place a 0.1 uF cap from Vcc to Ground, and from AVcc to Ground, close to the micro's pins.

You need these for reliable operation.

 

Next, it doesn't matter at all, but as a general rule one would use the power rail with the Red line for the Vcc rail, and the one with the Blue or Black line as the Ground rail.

If you use the "standard", and use it consistently, it will help you in the future.

 

On breadboards that do not have the colored lines you can use whatever layout you desire.

Notice on the photo I showed above that there is a piece of tape that shows the power rails: +3, Gnd, the breadboard, Gnd, +3.

So the outer rails are the Vcc rails, the inner rails are the Ground rails.

 

Again, it doesn't matter which you use, as long as you are consistent, and don't make a mistake!

 

I've learned, after years of breadboarding, to label the rails as the first thing I do.

 

Next: Know that the two red power rails and the two blue power rails are NOT connected to each other.

YOU have to jumper the two V+ and the two Ground rails together, if you are making Vcc and Ground connections on both sides of the breadboard.

This is in addition to jumpering the two ends of the power rails.

 

Finally, REMOVE all of your Reset circuitry.

I can't tell from your photo, but it isn't clear that you have it wired up correctly.

The micro has an internal pull up resistor on the Reset\ pin, and you don't need one, (at least for now).

 

Also, if you have the wrong sized capacitor on the Reset\ line then the programmer can't program the chip.

It will work fine without the cap, (at least for now).

 

Finally, (really, this time), develop good habits early.

A good habit / best practice is to draw a schematic diagram for every one of your projects.

They don't have to be fancy, you can draw it on the back of a napkin if you wish.

If, however, you pick a software package to draw them with, then you can copy and cut and paste, etc., to make future schematics even easier and faster to draw.

 

There is a Thread about schematic and PCB layout software.

 

There are advantages to having a schematic drawing package that is integrated into your PCB layout package.

You can worry about that later.

 

If you don't have another package on hand go to ExpressPCB and download their ExpressSchematic program.

It is free, it works well, and it will get you started.

 

Being old school, I draw lines that "jump" over other lines if there is no connection.

My old brain is used to doing it that way, and it is much easier for me than looking for a big dot if they connect, and the absence of one if they don't connect.

 

As you wire up your breadboard you can highlight each connection on a hard copy.

When every connection / part is highlighted, you know you haven't overlooked any connections.

 

An example of a M168 schematic is shown.

Not as fancy as some others, but functional, and a huge step over not having one at all.

 

JC

 

Please ignore the two "errors" on the schematic.

The Micro / GLCD's By-Pass Caps connect to +3V, not +5V, (copy / paste error!).

The GLCD's LED backlight connects to the Mega168, not to an Xmega...

 

Edit:  Mention the schematic errors

 

 

 

 

Last Edited: Tue. May 24, 2016 - 05:07 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the fault lies some how with the uart, arduino shows the port as"com3"

 

I have a feeling that it has something to do with the board choices in arduino, thus, which board choices would be suitable!?, it is a atmega328p with a listed arduino uno boot loader, so board = ardunio Uno? programmer = arduinoISP?

Last Edited: Wed. May 25, 2016 - 07:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Theone6000 wrote:

Hi all, i have been attempting to make a breadboard with an atmega328p chip and upload the blink sketch to it, all have thrown some sort of failure, I have attempted multiple ways to get around it, with no success!. they are generally like:-

 

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xf0

 

but also have 0X00, 0X20, 0X10, 0Xff, 

 

I am using the cp2102, i have checked the wires, got a 2nd chip(same errors), installed port driver(arduino sees it as "port 3"), and have searched lots for an answer with no avail!, when i plug the reset of the cp2102 into the reset of the atmega it throws:-

 

avrdude: ser_drain(): read error: The I/O operation has been aborted because of either a thread exit or an application request.

 

 it seems that no one knows what to do!

 

The Arduino resets the ATmega328 using the DTR signal.  If you are using the Arduino Bootloader, this is critical.  See this post.

 

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

using the DTR signal

And it seems the CTS signal also, I have used the later for M128 and M324 "Arduinos".

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

So i believe the atmega328 is bricked, of no real surprise, i thought something might have been wrong with it, as i think it has probably been sitting in the warehouse for years. So, the solution apparently is to supply a 16mhz signal to XTAL1, so, to do this on a leostick i would have to make an interrupt overflow and toggle the pin, correct? or is there a simpler way? i tried adding the code:-

void DoPulse() {
 // DDRB = 0xFF;
 pinMode(20,OUTPUT);
  while(1) {
  //  PORTB ^= 0xFF;
    digitalWrite(20,HIGH);
    delayMicroseconds(50);
    digitalWrite(20,LOW);
    delayMicroseconds(50);
    //_delay_us(50);
  }
}
but all it did was freeze the leostick(unfroze by hitting upload, then reset on the leostick), i believe because the code is in the main line of processor, as above the only way around i can see is to do an overflow, that means some pretty nifty code in the arduinoISP program for the leostick ATmega32U4!. any and all help greatly appreciated as i am only new to the port/pin/interrupt area!.

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

How do you know your micro "froze"?

Do you have an O'scope to look at the pin to see if the square wave was generated?

 

Your approach is fine, generate a square wave and inject it into the Xtal pin on the "bricked" micro.

 

Know that you also need a ground connection between the two micros.

 

Also, I would shorten the delay, to make the square wave a higher frequency.

 

JC

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

The green light just stayed on and didn't do a heartbeat, unfortunatly i don't have a O'scope, i connected the ground and the leostick suspended somehow, and when i took the ground off it reset!. 

I am going to make the delay 35 micros, and rewrite the code, the current problem is that the while loop never ends, so the loop never re-loops as it is only the much bigger chips that have multi thread capability!

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

Sorry, I don't know C, and I've only run one or two already written Arduino programs, so I can't debug your program.

 

BUT, I think you have a mis-understanding of how the program should work.

 

Most, (perhaps just about ALL), microcontroller programs always run a Main Loop and NEVER EXIT IT.

There is no operating system like there is on a PC.

You start a micro program and it runs forever, doing whatever it does.

In this case it simply outputs a square wave.

 

For small 8-bit micros it is unusual to run a "multi-threaded" program via a multi-tasking "OS", (although it can be done).

It is quite common to run interrupts which give the appearance of running multiple Threads simultaneously.

 

Bottom line, your program SHOULD loop forever.

 

For your square wave program you can add a 470 or 510 or 330 or anything in that range resistor and an LED, in series, connected to ground.

Then slow your program down for testing, make the delays 500 milliseconds, instead of microseconds.

You can now watch the LED flash if the program is running.

 

When you change back to a short delay the LED will appear to be dim, (1/2 on), as it will be flashing very quickly, and will be on 1/2 of the time.

 

Report back on your progress.

 

JC

 

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

I cannot find a good pin layout of the leostick which is making it hard(although i found a heartbeat on pin 9 i believe!), i tried changing pin numbers to see if i could pick one up, but to no success!. I called DoPulse() in the setup() and the code is:-

int TimerPin = 3;
void DoPulse(){
     pinMode(TimerPin,OUTPUT);
     while(1){
         if(digitalRead(TimerPin)){ digitalWrite(TimerPin,LOW); Serial.println("changed led"); }
         else{ digitalWrite(TimerPin,HIGH); }
         delay(500);
         }

    }

 

if the code is being called then it is not interfering with the green heartbeat light now, I also tried to do an interrupt:-

  bitSet(TIMSK1, TOIE1); (in the setup() )

  
ISR(TIMER1_OVF_vect){ 
    if(digitalRead(TimerPin)){ digitalWrite(TimerPin,LOW); Serial.println("changed led"); }
    else{ digitalWrite(TimerPin,HIGH); }
    delay(1000);
    }

 

I also couldn't print a message to the arduino serial monitor!?, tried Serial.print Serial.println SERIAL.print and nothing!, do i have to call the port specificaly, i.e. PORTB = 0b00001000; ???

thanks

Last Edited: Sat. May 28, 2016 - 01:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got the in-line code to work, and found the pin, but, as i said earlier, the inline code does not work, as the execution of the code does not get past the while loop(as above). Code executes along a path that is set by whoever wrote the code, if the person that wrote the code sends the path in a never ending loop, anyone on it will always go around in a loop until they die, as per the leostick. assigning a loop to another thread solves this as it is the equivalent of two paths, one can continually loop, the other go wherever!. Below will work once i work out what is taking control of pin 3

void loop(void) {
    if(digitalRead(TimerPin)){ digitalWrite(TimerPin,LOW); Serial.println("changed led"); }
    else{ digitalWrite(TimerPin,HIGH); }
    delay(500);  // for testing purposes
   // delayMicroseconds(35);  // to be adjusted to timer signal frequency and taking into account below loop operation time
    if (pmode){ digitalWrite(LED_PMODE, HIGH); }  // is pmode active?
    else{ digitalWrite(LED_PMODE, LOW); }
    if(error){ digitalWrite(LED_ERR, HIGH); } // is there an error?
    else{ digitalWrite(LED_ERR, LOW); }
    heartbeat();  // light the heartbeat LED
    if(SERIAL.available()){ avrisp(); }
    }

 

but, at the end of the day the signal is unreliable as once upload/chip-communication take place the signal will slow down, better to use interrupts, of which i am going to work out!

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

I cannot find a good pin layout of the leostick which is making it hard

Really? Is Google broken over your way?  smiley I found 10,300 results (0.24 seconds) for leostick and about 2 seconds later I found the full schematic.

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

no, just the freetronic atmega328, and some of the code that i have sourced, and some of the forums!