本帖最后由 donkey89 于 2010-1-10 13:58 编辑
在主模式下,把数据写入SPDR寄存器以后,发送完成SPIF就应该置位了吧?即使是MISO引脚悬空也应该置位的吧?下面的代码执行flash_read_id会死掉的,奇怪了void init_flash(void)
{
//IO的初始化
flash_port |=_BV(flash_cs);
flash_port |=_BV(flash_clk);
flash_ddr |=_BV(flash_cs);//falsh的片选
flash_ddr |=_BV(flash_di);//falsh的输入脚
flash_ddr |=_BV(flash_clk);//flash的时钟脚
//寄存器初始化
SPCR =_BV(SPE)|_BV(MSTR);//SPI使能,主模式
}
uint8_t spi_master_tran(uint8_t data)
{
SPDR=data;
while(!(SPSR & (1<<SPIF)));
//_delay_us(100);
return SPDR;
}
//读FLASH的设备号
void flash_read_id(uint8_t *id)
{
LOW_CS();
spi_master_tran(FLC_READ_ID);
*id++=spi_master_tran(0);
*id++=spi_master_tran(0);
*id++=spi_master_tran(0);
HIGH_CS();
}
|