簡體   English   中英

將帶有樹莓派的ArduinoID.hex文件上傳到attiny85

[英]Uploading the .hex file from ArduinoIDe with a raspberry pi to an attiny85

我,我正在編程attiny85。 首先,我是用樹莓派做的,並且可以制作一個程序來打開/關閉連接到attiny85的LED。 但是網上只有一個fex教程,可以使用rapiberry pi進行attiny編程,但是Arduino有很多教程。 因此,我決定使用arduino ide,然后獲取.hex文件,並將其與我的樹莓派一起上傳到attiny。 (我沒有arduino板)。 arduino ide上的更多信息使您的生活變得簡單。 但是,當我上傳它時,一切正常,但程序似乎無法正常工作。 我真的不知道是否可以使用arduino創建.hex文件並使用Raspberry pi進行推送。 附言:對不起英語不是我的母語這是我用覆盆子制作的第一個程序,誰工作:

#define F_CPU 1000000L
#include <avr/io.h>
#include <util/delay.h>
int main(void)
 {

    PORTB = 0xFF;   // LED's are off

  for (;;) {

     DDRB = 1<<DDB4 | 1<<DDB1 | 1<<DDB0 | 1<<DDB3;
    //PORTB ^= 0xFF;   // invert all the pins
     _delay_ms(1000); // wait some time
     DDRB = 0<<DDB4 | 0<<DDB1 | 0<<DDB0 | 0<<DDB3;
     _delay_ms(1000); // wait some time

   }
   return 0;
}

然后我用arduino制作的程序(我知道它應該只打開2 led,但沒有打開):

void setup() {

 pinMode(1, OUTPUT);
 pinMode(2, OUTPUT);

}


void loop() {
  digitalWrite(1, HIGH);
  digitalWrite(2, HIGH);
  delay(1000);              // wait for a second
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);  // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

為了推送它,我使用此命令(對於兩個程序,但是對於第一個程序,我首先編譯它以生成the.hex):

sudo gpio -g mode 22 out
sudo gpio -g write 22 0
sudo /usr/local/bin/avrdude -p t85 -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:blinky.hex

這樣正常嗎? 這是一個代碼問題,還是我無法嘗試? 我真的想使用arduino IDE,因為我希望我的attiny / rasbperry通過串行GPIO進行通信

也許您應該看看使用arduino庫並將其添加到項目中。 然后,當您使用avr gcc編譯器時,將添加該庫。 但是您的第二個代碼無法在attin上工作似乎很奇怪。 您是否檢查了.hex文件是否包含十六進制代碼? :)

好的,工作! :D實際上,要編譯/推送blinky.ci是使用makefile(我在tuto上找到了它)。 所以現在我只需要使用.hex並使用“ make install”,就像我第一次眨眼時所做的那樣,但是沒有編譯,因為我得到的是.hex而不是.c,所以這里的makefile :)

MCU=attiny85
AVRDUDEMCU=t85
CC=/usr/bin/avr-gcc
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=$(MCU)
OBJ2HEX=/usr/bin/avr-objcopy
AVRDUDE=/usr/local/bin/avrdude
TARGET=arduiblinky
# target = name of your file you want upload on the attiny

all : 
# no need this part if you have the .hex :D
    #$(CC) $(CFLAGS) $(TARGET).c -o $(TARGET)
    #$(OBJ2HEX) -R .eeprom -O ihex $(TARGET) $(TARGET).hex
    #rm -f $(TARGET)

install : all
    sudo gpio -g mode 22 out
    sudo gpio -g write 22 0
    sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 9600 - U flash:w:$(TARGET).hex
    sudo gpio -g write 22 1

noreset : all
    sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:$(TARGET).hex

fuse :
    sudo gpio -g mode 22 out
    sudo gpio -g write 22 0
    sudo $(AVRDUDE) -p $(AVRDUDEMCU) -P /dev/spidev0.0 -c linuxspi -b 10000 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m 
    sudo gpio -g write 22 1

clean :
    rm -f *.hex *.obj *.o

但是有人可以向我解釋為什么我使用make文件時它可以工作,為什么當我這樣做時它不能工作:

sudo gpio -g mode 22 out
sudo gpio -g write 22 0
sudo /usr/local/bin/avrdude -p t85 -P /dev/spidev0.0 -c linuxspi -b 10000 -U flash:w:blinky.hex

謝謝,我希望它可以幫助某人:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM