为什我的28377中自带的SPI读写外部的EEPROM不成功,怎么读数据都是0xff 主要函数如下
void main(void)
{
InitSysCtrl();
InitSpiaGpio();
InitPieVectTable();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
spi_init(); // init SPI.
EEPROM_CS = 1;
STA_READ();
for(;;)
{
RX_data=EEPROM_READ(0x00000);
}
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x0007; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR.all =0x0004;
SpiaRegs.SPICCR.all =0x0087; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF = a;
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0);
SPIBUF = SpiaRegs.SPIRXBUF;
}
void STA_READ()
{
EEPROM_CS = 0;
spi_xmit(RDSR);
EEPROM_CS = 1;
}
Uint16 EEPROM_READ(Uint16 address)
{
int addrH,addrL,addrHL,data=0;
addrH = 0;
addrL = 0;
addrHL = 0;
addrH = (address&0xff0000)>>16;
addrHL = (address&0x00FF00)>>8;
addrL = (address&0x0000ff);
EEPROM_CS = 0;
spi_xmit(READ);
spi_xmit(addrH);
spi_xmit(addrHL);
spi_xmit(addrL);
spi_xmit(0);
data=SpiaRegs.SPIRXBUF;
EEPROM_CS = 1;
return(data);
}
mangui zhang:
请确保28377输出的SPI接口时序满足EEPROM的读写要求
最好用示波器观察一下
为什我的28377中自带的SPI读写外部的EEPROM不成功,怎么读数据都是0xff 主要函数如下
void main(void)
{
InitSysCtrl();
InitSpiaGpio();
InitPieVectTable();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
spi_init(); // init SPI.
EEPROM_CS = 1;
STA_READ();
for(;;)
{
RX_data=EEPROM_READ(0x00000);
}
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x0007; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR.all =0x0004;
SpiaRegs.SPICCR.all =0x0087; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF = a;
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0);
SPIBUF = SpiaRegs.SPIRXBUF;
}
void STA_READ()
{
EEPROM_CS = 0;
spi_xmit(RDSR);
EEPROM_CS = 1;
}
Uint16 EEPROM_READ(Uint16 address)
{
int addrH,addrL,addrHL,data=0;
addrH = 0;
addrL = 0;
addrHL = 0;
addrH = (address&0xff0000)>>16;
addrHL = (address&0x00FF00)>>8;
addrL = (address&0x0000ff);
EEPROM_CS = 0;
spi_xmit(READ);
spi_xmit(addrH);
spi_xmit(addrHL);
spi_xmit(addrL);
spi_xmit(0);
data=SpiaRegs.SPIRXBUF;
EEPROM_CS = 1;
return(data);
}
xin he1:
回复 mangui zhang:
昨天 又测试了一下 ,DSP里面的SPI时序貌似不满足EEPROM的时序要求,比如我要用SPI协议传输 0x03 这几个字,但是示波器上看到的是0x0003.我需要八位八位的读,但是DSP却16位的读。有没有哪里可以改一下啊?
为什我的28377中自带的SPI读写外部的EEPROM不成功,怎么读数据都是0xff 主要函数如下
void main(void)
{
InitSysCtrl();
InitSpiaGpio();
InitPieVectTable();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
spi_init(); // init SPI.
EEPROM_CS = 1;
STA_READ();
for(;;)
{
RX_data=EEPROM_READ(0x00000);
}
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x0007; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR.all =0x0004;
SpiaRegs.SPICCR.all =0x0087; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF = a;
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0);
SPIBUF = SpiaRegs.SPIRXBUF;
}
void STA_READ()
{
EEPROM_CS = 0;
spi_xmit(RDSR);
EEPROM_CS = 1;
}
Uint16 EEPROM_READ(Uint16 address)
{
int addrH,addrL,addrHL,data=0;
addrH = 0;
addrL = 0;
addrHL = 0;
addrH = (address&0xff0000)>>16;
addrHL = (address&0x00FF00)>>8;
addrL = (address&0x0000ff);
EEPROM_CS = 0;
spi_xmit(READ);
spi_xmit(addrH);
spi_xmit(addrHL);
spi_xmit(addrL);
spi_xmit(0);
data=SpiaRegs.SPIRXBUF;
EEPROM_CS = 1;
return(data);
}
Eric Ma:
回复 xin he1:
SPICCR寄存器的位SPICHAR可以控制发送的字节长度。
ERIC