首页 > 解决方案 > 非常奇怪的 gpio 行为编程 ATtiny25v 与 avr-gcc 和 avrdude 通过树莓派

问题描述

我有一个 ATtiny25v 通过 SPI 连接到树莓派。

我使用 avr-gcc 来编译我的代码。然后我用avrdude上传。

但是我遇到了一个很奇怪的现象:main函数没有被调用,而是第一个函数的第一条指令对gpio有影响...

我在 portb4 上连接了一个 LED。

...我尝试了几个相同型号的芯片,它们的行为都相同(不包括一辆越野车)

...有人可以解释一下吗?

注意: 我省略了详细说明,但编译器 (with -Wall -pedantic) 和 avrdude (with -v -v) 都没有给出任何错误。

kcuzner 和上游版本(linux_gpio 修补http://savannah.nongnu.org/bugs/?47550)给出了相同的结果。kcuzner 使用 linuxspi 程序员的行为也一样。

这个 :

#include <avr/io.h>
#include <avr/interrupt.h>

#define B(b) (1 << b)

void ledT(){
   PORTB ^= B(PORTB4);
}

void led(uint8_t s){
   if(s)
      PORTB |= B(PORTB4);
   else {
      PORTB &= ~B(PORTB4);
   }
}

int main(){
   PORTB = 0;
   DDRB = 0;
   USISR = 0;
   USIDR = 0;
   while(1);
   //return 0;
}

...启动时 LED 上的灯。

#include <avr/io.h>
#include <avr/interrupt.h>

#define B(b) (1 << b)

void ledT(){
   PORTB ^= B(PORTB3);
}

void led(uint8_t s){
   if(s)
      PORTB |= B(PORTB4);
   else {
      PORTB &= ~B(PORTB4);
   }
}

int main(){
   PORTB = 0;
   DDRB = 0;
   USISR = 0;
   USIDR = 0;
   while(1);
   //return 0;
}

...保持 LED 关闭

和这个 :

#include <avr/io.h>
#include <avr/interrupt.h>

#define B(b) (1 << b)

void ledT(){
   PORTB ^= B(PORTB4);
   PORTB ^= B(PORTB4);
}

void led(uint8_t s){
   if(s)
      PORTB |= B(PORTB4);
   else {
      PORTB &= ~B(PORTB4);
   }
}

int main(){
   PORTB = 0;
   DDRB = 0;
   USISR = 0;
   USIDR = 0;
   while(1);
   //return 0;
}

...也使 LED 保持关闭状态。

#include <avr/io.h>
#include <avr/interrupt.h>

#define B(b) (1 << b)

void ledT(){
   PORTB = PORTB | B(PORTB3);
   PORTB = PORTB | B(PORTB4);
}

void led(uint8_t s){
   if(s)
      PORTB |= B(PORTB4);
   else {
      PORTB &= ~B(PORTB4);
   }
}

int main(){
   PORTB = 0;
   DDRB = 0;
   USISR = 0;
   USIDR = 0;
   while(1);
   //return 0;
}

...点亮 LED

标签: raspberry-piavravr-gccavrdude

解决方案


推荐阅读