使用 raspberry pi 从 ArduinoIDe 上传 .hex 文件到 attiny85

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

我,我正在为 attiny85 编程。首先,我用我的 raspberry pi 做到了,可以制作一个程序来关闭 on/turn 连接到我的 attiny85 的 LED。但是网上只有一个使用 raspberry pi 编程 attiny 的 fex 教程,但是有很多使用 Arduino 的教程。所以我决定 ided 使用 arduino ide,然后获取 .hex 文件并用我的 raspberry pi 将其上传到 attiny。 (我没有arduino板)。更多关于 arduino ide 有许多让你的生活变得简单的图书馆。但是当我上传它时一切正常,但程序似乎无法正常工作。我真的不知道是否可以用 arduino 创建 .hex 文件并用 Raspberry pi 推送。 Ps: 抱歉英语不是我的母语 这是我用树莓制作的第一个程序,谁在工作:

#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 但 none 是打开的):

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 编译器时,你添加库。但是你的第二个代码在阁楼上不起作用似乎很奇怪。您是否检查过 .hex 文件是否包含十六进制代码? :)

好的,成功了! :D 事实上,对于 compile/push blinky.c,我使用的是一个 makefile(我在 tuto 上找到它)。 所以现在我只使用 .hex 并使用“make install”,就像我对第一个 blinky 所做的那样,但没有编译,因为我得到的是 .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

谢谢,我希望它能对某人有所帮助:)