AnsweredAssumed Answered

SPI within XEP100 found the program stop in while(SPI0SR_SPIF==0)

Question asked by 刘 银 on Aug 2, 2017
Latest reply on Aug 7, 2017 by Radek Sestak

When I use SPI within XEP100 to write to  and read data   from an RAM chip(FM25640),I found the program stop in while(!SPI0SR_SPIF) ,I dont know how to solve this problem,anyone who have a good idea give me some suggestion,thank you!

Here are init ,write and read programs.

void SPI0_Init(void)
{

SPI_SO_DD=0;// MISO设置成输入

CS_D=1;
CS_DD=1;//SS设置为输出

SPI_SI=1;
SPI_SI_DD=1;//MOSI设置为输出

SPI_SCK=0;
SPI_SCK_DD=1;//SCK设置为输出

MODRR = 0x00;//使用SPI0口
SPI0CR1=0X52;//使能SPI模块为主模式,使能SPI0,禁止SPI中断CHOL CPHA = 00
SPI0CR2=0X10;//SS引脚作为通用IO,用户程序控制其信号。 通讯字节为8位
//SPI0BR=0X42; //设置通讯波特率,分频因子40
SPI0BR=0x77; //设置通讯波特率,分频因子2048
}
/***********************写一个字节********************/
unsigned char Write_Byte(unsigned char data)
{
unsigned char temp;
while(!SPI0SR_SPTEF);
SPI0DR=data;
while(!SPI0SR_SPIF);
return SPI0DR;
}
/***********************写数据********************/
void write_Data(unsigned int start_address,unsigned int length,unsigned char *dat)
{
unsigned int i;
CS_D=ON;
Write_Byte(WREN);
Write_Byte(WRITE);
Write_Byte(start_address >> 8);
Write_Byte(start_address);
for (i=0;i<length;i++)

{
Write_Byte(*dat);
dat++;
}
CS_D=OFF;
}
/**********************读一个字节************************/
unsigned char Read_Byte(void)
{
unsigned char rByte=0;
unsigned char temp;
while(!SPI0SR_SPIF);
rByte=SPI0DR;
return rByte;
}
/***********************读数据********************/
void Read_Data(unsigned int start_address,unsigned int length,unsigned char *dat)
{
unsigned int i;
CS_D=ON;
Write_Byte(READ);
Write_Byte(start_address >> 8);
Write_Byte(start_address);
for(i=0;i<length;i++)

{
*dat = Read_Byte() ;
dat++;

}
CS_D=OFF;

}

Outcomes