小弟测试eeprom通信功能,用的是SPI,发送数据功能正常,eeprom回来的数据波形也正确,只是无法读到正确的数据。附上代码
//SPI初始化
void InitSPI8bit(void)
{
EALLOW; GpioMuxRegs.GPFMUX.all |= 0x000F; // Select GPIOs to be SPI pins
EDIS;
SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
SpiaRegs.SPICCR.all=0x0007; // 8-bit character, Loopback mode disabled*
SpiaRegs.SPICTL.all=0x0006; // SPI Interrupt disabled, Master mode, Master/slave transmit enabled
SpiaRegs.SPISTS.all=0x0000;
SpiaRegs.SPIBRR=0x0026; SpiaRegs.SPIPRI.all=0x0040;
SpiaRegs.SPICCR.all=0x0087; // Enable SPI
}
//SPI发送
void eeprom_SPI_send8(Uint16 SPITXD)
{
Uint16 SPIBUF;
SpiaRegs.SPITXBUF = SPITXD;
while(SpiaRegs.SPISTS.all == 0) {} //wait for SPI send buf blank
SPIBUF = SpiaRegs.SPIRXBUF;
}
//接收函数
Uint16 eeprom_SPI_receive(void)
{
unsigned char SPIRXD_L,SPIRXD_H;
Uint16 SPIRXD;
SpiaRegs.SPITXBUF = 0x00; //发送伪数据
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0) {}
SPIRXD_H = SpiaRegs.SPIRXBUF ;
SpiaRegs.SPITXBUF = 0x00; //发送伪数据
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0) {}
SPIRXD_L = SpiaRegs.SPIRXBUF ;
SPIRXD = SPIRXD_H << 8 + SPIRXD_L;
return(SPIRXD);
}
出现问题为,运行接收程序,执行至while(SpiaRegs.SPISTS.bit.INT_FLAG == 0) {},就停止,求指导,急急急!!!
shuai wang2:
SpiaRegs.SPISTS.bit.INT_FLAG去查下这个标志是什么作用,你停在那肯定是因为一直SpiaRegs.SPISTS.bit.INT_FLAG=0
小弟测试eeprom通信功能,用的是SPI,发送数据功能正常,eeprom回来的数据波形也正确,只是无法读到正确的数据。附上代码
//SPI初始化
void InitSPI8bit(void)
{
EALLOW; GpioMuxRegs.GPFMUX.all |= 0x000F; // Select GPIOs to be SPI pins
EDIS;
SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
SpiaRegs.SPICCR.all=0x0007; // 8-bit character, Loopback mode disabled*
SpiaRegs.SPICTL.all=0x0006; // SPI Interrupt disabled, Master mode, Master/slave transmit enabled
SpiaRegs.SPISTS.all=0x0000;
SpiaRegs.SPIBRR=0x0026; SpiaRegs.SPIPRI.all=0x0040;
SpiaRegs.SPICCR.all=0x0087; // Enable SPI
}
//SPI发送
void eeprom_SPI_send8(Uint16 SPITXD)
{
Uint16 SPIBUF;
SpiaRegs.SPITXBUF = SPITXD;
while(SpiaRegs.SPISTS.all == 0) {} //wait for SPI send buf blank
SPIBUF = SpiaRegs.SPIRXBUF;
}
//接收函数
Uint16 eeprom_SPI_receive(void)
{
unsigned char SPIRXD_L,SPIRXD_H;
Uint16 SPIRXD;
SpiaRegs.SPITXBUF = 0x00; //发送伪数据
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0) {}
SPIRXD_H = SpiaRegs.SPIRXBUF ;
SpiaRegs.SPITXBUF = 0x00; //发送伪数据
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0) {}
SPIRXD_L = SpiaRegs.SPIRXBUF ;
SPIRXD = SPIRXD_H << 8 + SPIRXD_L;
return(SPIRXD);
}
出现问题为,运行接收程序,执行至while(SpiaRegs.SPISTS.bit.INT_FLAG == 0) {},就停止,求指导,急急急!!!
guangzhen zhang:
回复 shuai wang2:
接收移位结束,SpiaRegs.SPISTS.bit.INT_FLAG应该是硬件自动置1,可是没有置1是为什么呢?我初始化错误了吗?