The problem to use DSPI to communicate with M95256W

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The problem to use DSPI to communicate with M95256W

2,654 Views
xushengyu
Contributor II

hello, everyone! it is the first time to use MPC5644A to communicate with an external EEPROM (M95256W). Now, i can not receive data on SIN pin. who can help me? thank you in advance. there is my code.

Original Attachment has been moved to: code.txt.zip

0 Kudos
8 Replies

2,187 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

Why do you generate chip select by SW and do not use HW generated one and thus reuse continuous selection when accessing memory.

In your code you are using EOQ for each command, flag is not cleared later. Or better is it cleared but unintentionally because bit access is used to clear TCF and RFDF. Use rather full register access to clear particular flags, otherwise other can be cleared too.  

Anyway I can recommend to follow the code posted in https://community.nxp.com/thread/434481 .

 

If have an issue with reading the receive byte, then please share the bus signals to know what is really on the MISO pin.

BR, Petr

2,187 Views
xushengyu
Contributor II

Thank you very much! I tested the code below yesterday. But i found the clock is normal, the chip select is always low, the SOU pin of the MPC5644A is normal, the SIN pin of the MPC5644A is always high impendence. In addition, i do not know how to configure the timer correctly. Would you mind sending a code to me ? Thank you a lot! Here is my code.

#include "MPC5644A.h"
/*******************************************************************************
* Constants and macros
*******************************************************************************/
#define EEPROM_CMD_WREN 6
#define EEPROM_CMD_WRDI 4
#define EEPROM_CMD_WRITE 2
#define EEPROM_CMD_RDSR 5
#define EEPROM_CMD_READ 3
#define LED SIU.GPDO[219].R
#define WIP 0x01

uint8_t txData[]={"Hello...."};
uint8_t rxData[10];


/***********************************************
system Initialization
************************************************/
void initSysclk (void)
{
FMPLL.ESYNCR1.B.CLKCFG = 0X7; /* Change clk to PLL normal from crystal*/
FMPLL.SYNCR.R = 0x16080000; /* 8 MHz xtal: 0x16080000; 40MHz: 0x46100000 */
while (FMPLL.SYNSR.B.LOCK != 1) {}; /* Wait for FMPLL to LOCK */
FMPLL.SYNCR.R = 0x16000000; /* 8 MHz xtal: 0x16000000; 40MHz: 0x46080000 */
}

/****************************************************
SIU I nitialization
*****************************************************/
void SIU_Init(void)
{
SIU.PCR[102].R = 0x0600; //clock
SIU.PCR[103].R = 0x0500; //SIN
SIU.PCR[104].R = 0x0600; //SOU
SIU.PCR[106].R = 0x0600; //CS 

}
void Delay(int m)
{
int ii,jj;
if (m<1) m=1;
for(ii=0;ii<m;ii++)
for(jj=0;jj<400;jj++){}
}

/*******************************************
DSPI_B Initialization
*******************************************/
void DSPI_Init(void)
{
DSPI_B.MCR.R = 0x80010001; /* Configure DSPI as master */
DSPI_B.CTAR[0].R = 0x38044425; /* Configure CTAR0 */         i do not know whether the CATR[0] is right
DSPI_B.MCR.B.HALT = 0x0; /* Exit HALT mode: go from STOPPED to RUNNING state*/
}

static uint8_t Write_Byte(uint16_t cmd, uint16_t data)
{
uint16_t response = 0x0000;
DSPI_B.PUSHR.R = (uint32_t)((uint32_t)(cmd<<16) + data); /**/
while (DSPI_B.SR.B.RFDF != 1){} /* Wait for Receive FIFO Drain Flag = 1 */
response = (uint8_t)DSPI_B.POPR.R; /* Read data received by master SPI */

DSPI_B.SR.R = 0x80020000;

return((uint8_t)(0xFF & response));       //When i debug, the response is always 0xFF

}

void EEPROMWriteEnable(void)
{
Write_Byte(0x0001,EEPROM_CMD_WREN);
}

uint8_t EEPROMReadRDSR(void)
{
uint8_t response;
//read register status EEPROM_CMD_RDSR equal 5
response = Write_Byte(0x8001,EEPROM_CMD_RDSR);
response = Write_Byte(0x0001,0); // dummy byte to read status

return response;
}

void EEPROMWriteBytes(uint16_t Address, uint8_t *pWriteData, uint8_t DataSize)
{
uint8_t response,i,addrH,addrL;

addrH = ((Address&0xFF00)>>8);
addrL =(Address&0x00FF) ;

response = Write_Byte(0x8001,EEPROM_CMD_WRITE); /*command write */
response = Write_Byte(0x8001,addrH); //high address byte/
response = Write_Byte(0x8001,addrL); //low address byte/
for (i = 0; i < (DataSize-1); i++)
{
response = Write_Byte(0x8001,*pWriteData++);
}
response = Write_Byte(0x0001,*pWriteData); // write last data byte

}

uint8_t EEPROMReadBytes(uint32_t Address, uint8_t *pReadData, uint8_t DataSize)
{
uint8_t response,i,addrH,addrL;

addrH = (Address&0xFF00)>>8;
addrL = Address&0x00FF;

response = Write_Byte(0x8001, EEPROM_CMD_READ);

response = Write_Byte(0x8001,addrH); //high address byte/
response = Write_Byte(0x8001,addrL); //low address byte/

for (i = 0; i < (DataSize-1); i++)
{
*pReadData++ = Write_Byte(0x8001,0); // dummy byte to read data
}
*pReadData = Write_Byte(0x0001,0); // dummy write for last last data read

}
/*******************************************************************************
* Global functions
*******************************************************************************/
void main (void)
{
uint8_t status;

initSysclk();
INTC_Init();    // I have no idea to configure INTC, Can you help me?

SIU_Init();

DSPI_Init();

EEPROMWriteEnable();

EEPROMWriteBytes(0,&txData[0],6);

status=EEPROMReadRDSR();

EEPROMReadBytes(0,&rxData[0],6);

while(1)
{

}
}

0 Kudos

2,187 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

You configured PCR[106] for DSPI_B_PCS1, so if this pin is really connected to the memory /S pin then the command parameter in WRITE_Byte function must be 0x8002 and 0x0002. The “2’ means the PCS1 will be driving by HW.

Also once you write the bytes to the memory you have to wait until write is done internaly. The status register is checked against WIP bit

EEPROMWriteBytes(0,&txData[0],6);

while(0x1 & EEPROMReadRDSR()){};

EEPROMReadBytes(0,&rxData[0],6);

BR, Petr

2,187 Views
xushengyu
Contributor II

Hi, Petr. Thank you! I modified the code as your suggestion. But, it is not work. when i debug, and set breakpoints. it is always waiting for writing is done. In another word, the code stopped here(while(0x1 & EEPROMReadRDSR()){};). I found the response was 0XFF, and it never ever changed. The question puzzled me a few days. Now, i do not know what should i do. I have no idea to solve the problem. I feel helpless! 

0 Kudos

2,187 Views
PetrS
NXP TechSupport
NXP TechSupport

share the memory circuitry and connection with the MCU.

BR, Petr

0 Kudos

2,187 Views
xushengyu
Contributor II

Thank you for your reply! Here is my circuit. Thank you for your help!图片1.jpg

0 Kudos

2,187 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

the connection looks correct.

As you are using PCS1 for chip select, use following line within a DSPI init to have PCS1 inactive high.

DSPI_B.MCR.R = 0x80020001; /* Configure DSPI as master */

If nothing helps, please share the bus signals taken by oscilloscope/analyzer.

BR, Petr

2,187 Views
xushengyu
Contributor II

Thank you! Ido not have four channel oscilloscope. I read the datasheet of M95256, chapter 6.3(read status register) . It explained the register can be read at any time. Here is the signal which is taken by the oscilloscope. The blue is the clock signal, the yellow is the SOU pin of the MPC5644A. And the chip select is always low, the SIN pin of the MPC5644A is always high impendence. what should i do now?  

IMG_20170904_131709.jpg

0 Kudos