Problem uploading a sketch to an atmega 328p - Page 1
Forum section: electronics / general

author: antoniobeta
author_rank: Contributor
timestamp: December 26, 2016, 10:30:59 am
content: 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.

author: retrolefty
author_rank: Super Contributor
timestamp: December 26, 2016, 01:23:22 pm
content: 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.

author: antoniobeta
author_rank: Contributor
timestamp: December 26, 2016, 01:50:47 pm
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: December 26, 2016, 02:36:46 pm
content: 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.

author: antoniobeta
author_rank: Contributor
timestamp: December 26, 2016, 02:44:57 pm
content: Quote from: Ian.M on December 26, 2016, 02:36:46 pmopps I am sorry, I misspelled it, I mean DTR.

author: TheDane
author_rank: Regular Contributor
timestamp: December 26, 2016, 09:30:33 pm
content: Looking at your schematic, it seems you are missing a decoupling capacitor across Vcc and Gnd.- you have put in 5Vreg, so Iguessthere 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 thecorrectbaud rate/port you need to program the sketch.

author: sleemanj
author_rank: Super Contributor
timestamp: December 27, 2016, 12:07:01 am
content: Quote from: antoniobeta on December 26, 2016, 10:30:59 amThis 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.

author: antoniobeta
author_rank: Contributor
timestamp: December 27, 2016, 12:07:01 pm
content: 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 failsavrdude: stk500_recv(): programmer is not respondingavrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xd4Also thats my full schematic

author: sleemanj
author_rank: Super Contributor
timestamp: December 27, 2016, 12:14:23 pm
content: Quote from: antoniobeta on December 27, 2016, 12:07:01 pmWell that shows you can transmitfromthe ATMega, but it doesn't show that you can transmittoit. You should check that your comms works in both directions.

author: antoniobeta
author_rank: Contributor
timestamp: December 27, 2016, 12:35:01 pm
content: @sleemanjQuoteYou are rightI have uploaded this sketck:/* Simple Serial ECHO script : Written by ScottC 03/07/2012 *//* Use a variable called byteRead to temporarily storethe data coming from the computer */byte byteRead;void setup() {// Turn the Serial Protocol ONSerial.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?

author: MickM
author_rank: Regular Contributor
timestamp: December 28, 2016, 01:53:48 pm
content: 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 boardsm328 CP2101-----------------------DTR DTRRX TXTX RXVCC 5VGND CTS (not con)GND GNDNote that CTS on the CP2102 is not connected.You would do m328 DTR to cable RTSExactly 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

author: antoniobeta
author_rank: Contributor
timestamp: December 29, 2016, 11:50:04 am
content: Quote from: MickM on December 28, 2016, 01:53:48 pmI 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.

author: antoniobeta
author_rank: Contributor
timestamp: December 29, 2016, 11:58:57 am
content: 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 datasheetThis behaviour is deprecated and will result in an error in future versionYou 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.

author: MickM
author_rank: Regular Contributor
timestamp: December 29, 2016, 03:17:11 pm
content: Hi;The config bits problem is probably related to this from "revisions.txt" Arduino 8." ARDUINO 1.8.0 - 2016.12.20...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.