2015年6月16日 星期二

用FTDI燒錄Atmege328p


之前一直使用arduino uno當作atmega的燒錄器,

但是每次要燒錄時都要把線拔掉,

雖然不是有特別的障礙,但總是覺得有點麻煩。


於是花了一百多塊台幣,在網路上買了一個燒錄arduino的USB to TTL的FTDI小板,

背面寫著Deek-Robot,
(焊點旁助焊劑的痕跡超明顯。  完全符合他的價格)

 (照片來自一位外國先生的網誌,google翻譯了一下好像不是在說這東西好話的樣子)


收到之後,試了半天,完全燒不進去,一直跳出下面的錯誤訊息

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


然後就一路從1 of 10數到10 of 10,
ZzZzZz..
接著就燒錄失敗


找了一堆資料之後,與有同樣症頭的朋友們分享。

**有人說IC裡面要有bootloader,由於我沒有沒有bootloader的IC,所以沒有試驗。


1.麵包板圖

(裡面的FTDI電路板是fritzing內建的,接腳一樣)




2.電路圖

一開始完全無法工作的硬體問題就是出在,
DTR要連到C3那顆0.1uf(104)的陶瓷電容,再接到RESET,
 但是我沒有104的電容,
只有103的陶瓷電容,可以工作。
也試了104的塑膠電容,也可以工作。



 3. 軟體設置



板子要設置成arduino duemilanove or diecimila
處理器選你的IC,我是Atmega328所以就選這個,
之後就直接按上傳就好
各位可以試試看blink的程式試試看有沒有成功囉





 /* Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(500);              // wait for a second
}

ps:可以燒錄sketch,不能燒錄bootloader喔, 要燒錄bootloader的話可以用arduino uno當作ISP方式燒錄。 謝謝各位。

參考資料
 在麵包板上建構Arduino(ATmega328P加USB轉TTL Serial轉接卡)  by 葉難



UPDATE
2015/06/17 00:51

剛剛換了一顆IC,就沒辦法燒錄,

後來把軟體的board改成arduino uno之後又可以了...

(一樣的IC,一樣的接線)


Overriding Baud Rate          : 115200


只要是57600或是其他不是115200的數值就會失敗。


莫名其妙。




UPDATE
2015/06/17 01:00
有時顯示Overriding Baud Rate          :57600也可以燒錄

燒錄要靠運氣。
有時可以,有時不行, 

原因不明。

:'(

這個100多塊錢的FTDI不穩定。
跟第一張圖的原作者說的一樣。



UPDATE
2015/06/17


都要做一塊PCB了,就做成共用的,

FTDI以及UNO燒錄的腳位,都放上快速插座預留。

這樣就算被FTDI弄得一肚子鳥氣的時候,

還是可以搬出UNO來對應。


UNO燒錄方法

由於硬體把LED抓到了第9腳去, 要測試有沒有成功燒錄,就試試看這個呼吸燈code吧。
 
int brightness = 0;
int fadeAmount = 5;
int delayDuration = 30; 

void setup() {
  pinMode(9, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
analogWrite(9, brightness);
  brightness = brightness + fadeAmount;
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount ;
}
delay(delayDuration);                     
}
實測OK

o'_'o




ps2:查詢的過程中,看到了一句話覺得很有意思,分享給大家。

"If you want to build a ship, don't drum up people to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea" - Antoine de Saint-Exupéry

如果你要打造一艘船,比起讓人們去撿木頭或安排他們工作,更好的方法是激發他們對海洋的熱情。
(以上我亂翻的啦,英文不好請見諒)

沒有留言:

張貼留言