raspberry-pi - 非常奇怪的 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
解决方案
推荐阅读
- gatsby - Gatsby + Contentful + Netlify - 如何在生产中渲染 tracedSVG 图像?
- database - 设计具有一个时间戳值和多行和多列数据的表的最佳方法是什么?
- javascript - Wordpress:在function.php中排队后没有加载javascript
- mysql - 我的查询将被执行正确吗?
- python - 在 .txt 文件中按时间对行进行排序
- python-3.x - 使用多个 CPU 使用 Keras 模型进行预测
- node.js - 如何将图像下载为流然后上传?
- azure - 在 Azure SignalR 中配置到 hubContext.Clients.User 的声明映射
- sql - SQL 不显示结合 where 条件的视图
- r - 是否可以从 R 中的 k 均值聚类计算密度图?