Author Topic: Problem uploading a sketch to an atmega 328p  (Read 4494 times)

0 Members and 1 Guest are viewing this topic.

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Problem uploading a sketch to an atmega 328p
« on: December 26, 2016, 10:30:59 am »
Hi guys.
I have done an arduino based board following this schematic and I am not able to upload any  scketch using my sparkfun ftdi board. I am using the arduino IDE 1.6.9 and I am able to burn the bootloader using my UNO, also, using my uno I can upload the sketch, trought the ICSP connector. Of course I reburn the bootloader before triying to reupload the sketch using the ftdi board.

I canĀ“t find anything grong on the schematic. Do you see something? Could it be other thing?

PD. between the board and the FTDI programer I have got another board that connects the CTS pin to GND, and changes RX and TX possitions so RX on the board is conected to TX on the atmega and TX to RX.
Also, the jumper is closed.
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Problem uploading a sketch to an atmega 328p
« Reply #1 on: December 26, 2016, 01:23:22 pm »
You say you can upload a sketch using ICSP, but not via normal bootloader. If that is true then your next step is to upload a sketch (via ICSP) that just tests out the serial data (send and rec) to test via the serial monitor on the IDE, just have the sketch 'echo' anything received back out the send path.

 

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Re: Problem uploading a sketch to an atmega 328p
« Reply #2 on: December 26, 2016, 01:50:47 pm »
I think that programer is working because the tx led lights showing that it is sending but it waits for a reponse that never comes. I still think that the problem is on the CTS reset, maybe it needs a bigger cap?
I wil try what you are saing to know if serial comunication works and later I will post the result. Thanks for your help.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Problem uploading a sketch to an atmega 328p
« Reply #3 on: December 26, 2016, 02:36:46 pm »
CTS reset?  :-//

Unless your adapter is labelled as a DCE device (normally PC serial ports are DTE because the original IBM PC could be used to replace a dumb terminal), CTS is an input used for local flow control.   Try RTS or DTR - AVRDUDE can use either.   If in doubt whether its DCE or DTE, check the line you want to drive /RESET from is an output using a DMM and if it seems to be floating, confirm its an input by using a 10K resistor to pull it high then low to see if its actually floating.
 

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Re: Problem uploading a sketch to an atmega 328p
« Reply #4 on: December 26, 2016, 02:44:57 pm »
CTS reset?  :-//

Unless your adapter is labelled as a DCE device (normally PC serial ports are DTE because the original IBM PC could be used to replace a dumb terminal), CTS is an input used for local flow control.   Try RTS or DTR - AVRDUDE can use either.   If in doubt whether its DCE or DTE, check the line you want to drive /RESET from is an output using a DMM and if it seems to be floating, confirm its an input by using a 10K resistor to pull it high then low to see if its actually floating.

opps I am sorry, I misspelled it, I mean  DTR.
 

Offline TheDane

  • Regular Contributor
  • *
  • Posts: 209
  • Country: dk
Re: Problem uploading a sketch to an atmega 328p
« Reply #5 on: December 26, 2016, 09:30:33 pm »
Looking at your schematic, it seems you are missing a decoupling capacitor across Vcc and Gnd.
- you have put in 5Vreg, so I guess there might be a cap elsewhere. If not, this can be a big trouble causer.

Do you get any errors in the Arduino IDE? (Wrong port, Time outs, etc.)
Have you verified your usb-serial device works ok (a simple loop-back of characters, when rx-tx is shorted) at the correct baud rate/port you need to program the sketch.



« Last Edit: December 26, 2016, 09:32:58 pm by TheDane »
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Problem uploading a sketch to an atmega 328p
« Reply #6 on: December 27, 2016, 12:07:01 am »
PD. between the board and the FTDI programer I have got another board that connects the CTS pin to GND, and changes RX and TX possitions so RX on the board is conected to TX on the atmega and TX to RX.

This is pretty confusing.  Just to be clear.  The TX pin on the ATMega must be connected to the RX pin on your USB-Uart device (FTDI), and vice-versa.

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Re: Problem uploading a sketch to an atmega 328p
« Reply #7 on: December 27, 2016, 12:07:01 pm »
Ok guys,
I have test the programer, uploading that code to the board, using my UNO as ISP programer,

void setup() {
  Serial.begin(9600);
  }

void loop() {
  Serial.print("test1");
}


afther uploading is done, I conected the FTDI board an I am able to read test1 trought the serial without any problem.

Afther that, I have reburn the bootloader am tried to upload a sketch by serial again and the arduino IDE keeps "uploading" until it fails


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xd4


Also thats my full schematic
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Problem uploading a sketch to an atmega 328p
« Reply #8 on: December 27, 2016, 12:14:23 pm »

afther uploading is done, I conected the FTDI board an I am able to read test1 trought the serial without any problem.


Well that shows you can transmit from the ATMega, but it doesn't show that you can transmit to it.  You should check that your comms works in both directions.


~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Re: Problem uploading a sketch to an atmega 328p
« Reply #9 on: December 27, 2016, 12:35:01 pm »
@sleemanj
Quote
Well that shows you can transmit from the ATMega, but it doesn't show that you can transmit to it.  You should check that your comms works in both directions.

You are right
I have uploaded this sketck:

/* Simple Serial ECHO script : Written by ScottC 03/07/2012 */

/* Use a variable called byteRead to temporarily store
   the data coming from the computer */
byte byteRead;

void setup() {               
// Turn the Serial Protocol ON
  Serial.begin(9600);
}

void loop() {
   /*  check if data has been sent from the computer: */
  if (Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read();
    /*ECHO the value that was read, back to the serial port. */
    Serial.write(byteRead);
  }
}


And I am not getting any reply when I send something. Also tried the program on the UNO and works fine.
We have a problem with tx no? Maybe the decoupling caps?
« Last Edit: December 27, 2016, 02:09:44 pm by antoniobeta »
 

Offline MickM

  • Regular Contributor
  • *
  • Posts: 100
Re: Problem uploading a sketch to an atmega 328p
« Reply #10 on: December 28, 2016, 01:53:48 pm »
So in a nutshell the 328 works from ISP but not from ICSP using the FTDI cable from Sparkfun.
The problem is the cable.

Also from Sparkfun's website:
https://www.sparkfun.com/products/9717
" Originally, the cable was designed to have 3.3V VCC, however something was lost in translation between SparkFun and our supplier and we got stuck with a whole bunch of FTDI cables that have a slight mix up in wiring. These have 5V VCC, and 3.3V I/O. "

Also: "The FTDI Basic uses DTR to cause a hardware reset where the FTDI cable uses the RTS signal."

So not the best cable to begin with.

avrdude does a logical OR to RTS and DTR - making them the same.

http://www.deanmao.com/2012/08/12/fixing-the-dtr-pin/

I use a CP2102 based USB to serial adapter for FTDI comms.
Here is the pinouts and connections as on the boards

 m328  CP2101
-----------------------
DTR     DTR
RX      TX
TX      RX
VCC   5V
GND  CTS (not con)
GND   GND
 Note that CTS on the CP2102 is not connected.

You would do m328 DTR to cable RTS

Exactly how are you connected?
Does your M328 get power?
is it correct? (not 3v3 by mistake)
I always add an LED for power.

Also in the Arduino IDE you must select the board, the CPU, and CPU clock speed.
In my case I use Pro-minis, both 3v3 and 5V, and 8 and 16MHz.
If you select the wrong clock, serial comms will not work (garbage), although programming will.

Mick M

 

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Re: Problem uploading a sketch to an atmega 328p
« Reply #11 on: December 29, 2016, 11:50:04 am »

Exactly how are you connected?
Does your M328 get power?
is it correct? (not 3v3 by mistake)
I always add an LED for power.


I am connected using this board (https://www.sparkfun.com/products/9716), trough the conector on my schematic, but sitching RX to TX and TX to RX and also conecting CTS to ground.
M328 gets it power from the sparkfun board.
It is set to 5v yes.

 

Offline antoniobetaTopic starter

  • Contributor
  • Posts: 20
  • Country: es
Re: Problem uploading a sketch to an atmega 328p
« Reply #12 on: December 29, 2016, 11:58:57 am »
I have noticed what would be a problem. (I post it on another reply for get the topic cleaner, if it is worg, jus tell me, and I wont make it again).
On arduino 1.05 I am not gettin any errors burning the bootloader.

But on arduino 1.8 (I have just updated today) I am getting this error:
***failed; 
avrdude: WARNING: invalid value for unused bits in fuse "efuse", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xfd instead of 0x05 (double check with your datasheet first).


Edit, also on arduino 1.6.9, any errors. But the errors appears on arduino 1.6.12.
« Last Edit: December 29, 2016, 12:06:57 pm by antoniobeta »
 

Offline MickM

  • Regular Contributor
  • *
  • Posts: 100
Re: Problem uploading a sketch to an atmega 328p
« Reply #13 on: December 29, 2016, 03:17:11 pm »
Hi;
  The config bits problem is probably related to this from "revisions.txt" Arduino 8.
" ARDUINO 1.8.0 - 2016.12.20

[ide]
...
avrdude: Added fake configuration for EFUSE on atmega8 part. This solves a long standing issue with "Burn bootloader".
  Thanks @rigelinorion, @awatterott"


I do not know why you are grounding CTS.
Unhook it - it is not needed.
Try to wire it the way I did.

Mick M.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf