The PIC microcontroller cannot communicate with FM25V05 normally, the code is as follows

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
LONGNIGHT
Level 1
Level 1
5 sign-ins First reply posted First question asked

/**************************************************
SPI串口初始化
****************************************************/
void SPI_Init(void)
{
SDOSEL = 0; //RC2为SDO

TRISC = 0B00001010; //RC1 input SDI = 1
//RC0 output SCK = 0
//RC2 output SDO = 0
//RC3 INTPUT SS = 1
TRISA = 0B00000010;
//mode 3 CKP = 1,CKE = 1;上升沿发送
SSP1STAT = 0b01000000; // CKE = 1
SSP1CON1 = 0b00110000; // 主模式 WCOL =0;SSP1OV = 0;SSP1EN =1;CKP = 1
SSP1ADD = 0;
SPI_CS=0; //启动从机
WriteSPI(0x06); //写入使能wren指令
SPI_CS=1; //停止从机
__delay_us(10);
SPI_CS=0; //启动从机
WriteSPI(0x01); //写状态寄存器指令
WriteSPI(0x80); //写状态字无保护
SPI_CS=1;
}

/******************************************
WriteSPI 写单字节缓冲储存器
*******************************************/
void WriteSPI(unsigned char i)
{
SSP1IF=0; // clear SSP interrupt bit
SSP1BUF=i;
while(!SSP1IF); // Wait for interrupt flag to go high indicating transmission is complete
}
//**************************************************************************************
// ReadSPI 读单字节缓冲
//**************************************************************************************
unsigned int ReadSPI(void)
{
unsigned char databyte;
SSP1IF=0; // Clear SSP interrupt bit
SSP1BUF = 0x00; // Write dummy data byte to the buffer to initiate transmission
while(!BF); // Wait for interrupt flag to go high indicating transmission is complete
databyte = SSP1BUF; // Read the incoming data byte
return (databyte);
}

//*************************************************************************************
// 从储存器读标志位
//**************************************************************************************
unsigned char Read_SPI_StatusReg(void)
{
unsigned char data_read;

SPI_CS=0;
WriteSPI(0x05); // Send read status register command
data_read = ReadSPI(); // Read the data
SPI_CS=1;
return(data_read);
}

//**************************
//写一个字节进储存器
//**************************
void Write_SPI_Byte(unsigned int address_hi,unsigned int address_lo,unsigned int data)
{
// unsigned int StatusReg;

SPI_CS=0;
WriteSPI(0x06); // Send the set write enable latch command
SPI_CS=1;
__delay_us(10);

SPI_CS=0;
WriteSPI(0x02); // Send write command
WriteSPI(address_hi); // Send high address byte
WriteSPI(address_lo); // Send low address byte
WriteSPI(data); // Send data byte
SPI_CS=1;

}

//********************************
// 从储存器里读一个字节
//********************************
unsigned char Read_SPI_Byte(unsigned int address_hi,unsigned int address_lo)
{
unsigned char readdata;

SPI_CS=0;
WriteSPI(0x03); // Send read command
WriteSPI(address_hi); // Send high address
WriteSPI(address_lo); // Send Low address byte
readdata = ReadSPI(); // Read the data
SPI_CS=1;
return(readdata);
}

0 Likes
1 Solution
PradiptaB_11
Moderator
Moderator
Moderator
500 replies posted 250 solutions authored 250 replies posted

Hi,

Can you upload the scope shots for a read and write operation on the FRAM. Is there any signal on the SPI bus or the scope shots show nothing. If we are not getting any signal on the SPI bus then the code and the schematics/ connections need to be reviewed to debug the error.

Thanks,

Pradipta. 

View solution in original post

0 Likes
2 Replies
PradiptaB_11
Moderator
Moderator
Moderator
500 replies posted 250 solutions authored 250 replies posted

Hi,

Can you upload the scope shots for a read and write operation on the FRAM. Is there any signal on the SPI bus or the scope shots show nothing. If we are not getting any signal on the SPI bus then the code and the schematics/ connections need to be reviewed to debug the error.

Thanks,

Pradipta. 

0 Likes
LONGNIGHT
Level 1
Level 1
5 sign-ins First reply posted First question asked

thank you,I passed the debugging

0 Likes