XMC4502 SPI receive problem

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

cross mob
ChrisMarquesIta
Level 1
Level 1
First reply posted First question asked Welcome!

I'm using an XMC4502 and I'm trying to write and read to an spi eeprom (CAT25640).

Write sequence seems correct, the oscilloscope signals are ok.

Read sequence is not ok, MISO is alway high and doesn't change.

Is the configuration correct?

Thanks

#define SPI_CS_PIN P0_9
#define SPI_MISO_PIN P0_0
#define SPI_MOSI_PIN P0_1
#define SPI_CLK_PIN P0_10

/**
* @brief SPI configuration structure
*/
XMC_SPI_CH_CONFIG_t spi_config =
{
.baudrate = 1000000,
.bus_mode = XMC_SPI_CH_BUS_MODE_MASTER,
.selo_inversion = XMC_SPI_CH_SLAVE_SEL_INV_TO_MSLS,
.parity_mode = XMC_USIC_CH_PARITY_MODE_EVEN
};

XMC_GPIO_CONFIG_t spi_pin_out_config = {
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2
};

XMC_GPIO_CONFIG_t spi_pin_in_config = {
.mode = XMC_GPIO_MODE_INPUT_PULL_UP
};

 

void SPI_Initialize(void)
{
/*Initialize and Start SPI*/
XMC_SPI_CH_Init(XMC_SPI1_CH1, &spi_config);

XMC_SPI_CH_SetBitOrderMsbFirst(XMC_SPI1_CH1);

XMC_SPI_CH_SetWordLength(XMC_SPI1_CH1, (uint8_t)8);


/*Input source selected*/
XMC_SPI_CH_SetInputSource(XMC_SPI1_CH1,XMC_SPI_CH_INPUT_DIN0,USIC1_C1_DX0_P0_0); // pag 1579/1814 manual infineon xmc4500

XMC_SPI_CH_Start(XMC_SPI1_CH1);

/*GPIO configuration*/
XMC_GPIO_Init(SPI_CS_PIN, &spi_pin_out_config);
XMC_GPIO_Init(SPI_MISO_PIN, &spi_pin_in_config);
XMC_GPIO_Init(SPI_MOSI_PIN, &spi_pin_out_config);
XMC_GPIO_Init(SPI_CLK_PIN, &spi_pin_out_config);
}

 

void E2P_SendCommand(uint8_t bCmd)
{
XMC_SPI_CH_SetWordLength(XMC_SPI1_CH1, (uint8_t)8);

/*Sending a byte*/
XMC_SPI_CH_Transmit(XMC_SPI1_CH1, bCmd, XMC_SPI_CH_MODE_STANDARD);

/*Wait till the byte has been transmitted*/
while((XMC_SPI_CH_GetStatusFlag(XMC_SPI1_CH1) & XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION) == 0U);
XMC_SPI_CH_ClearStatusFlag(XMC_SPI1_CH1, XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION);
}


void E2P_SendData(uint16_t wData)
{
XMC_SPI_CH_SetWordLength(XMC_SPI1_CH1, (uint8_t)16);

/*Sending a byte*/
XMC_SPI_CH_Transmit(XMC_SPI1_CH1, wData, XMC_SPI_CH_MODE_STANDARD);

/*Wait till the byte has been transmitted*/
while((XMC_SPI_CH_GetStatusFlag(XMC_SPI1_CH1) & XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION) == 0U);
XMC_SPI_CH_ClearStatusFlag(XMC_SPI1_CH1, XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION);
}


// ___________________________________________________________________________
// function name
// Note :
// ___________________________________________________________________________
uint16_t E2P_ReadData (void)
{
uint16_t readData;

readData = XMC_SPI_CH_GetReceivedData(XMC_SPI1_CH1);
return readData;
}

 

// ___________________________________________________________________________
// function name
// Note :
// ___________________________________________________________________________
uint16_t E2P_WriteCell(uint16_t wPos, uint16_t wVal)
{
if ( wPos >= E2P_NUMALLCELLE )
return E2P_MAX_NUMCELLE;
else if ( E2P_bFase != E2P_IDLE )
return E2P_IS_BUSY;
else
{
E2P_Driver(E2P_WREN, 0, 0);
E2P_Driver(E2P_WRITE, wPos, wVal);
return E2P_WRITE_OK;
}
}

// ___________________________________________________________________________
// function name
//
// ___________________________________________________________________________
uint16_t E2P_ReadCell(uint16_t wPos)
{
if ( wPos < E2P_NUMALLCELLE )
return E2P_Driver(E2P_READ,wPos,0);
else
return (0xa55a);
}

uint16_t E2P_Driver(uint8_t bComando, uint16_t wPos, uint16_t wValore)
{
uint16_t wTmp = 0;XMC_SPI_CH_EnableSlaveSelect(XMC_SPI1_CH1, XMC_SPI_CH_SLAVE_SELECT_0);

switch (bComando)
{
case E2P_WRITE :
E2P_SendCommand(bComando);
E2P_SendData(wPos);
E2P_SendData(wValore);
break;

case E2P_READ :
E2P_SendCommand(bComando);
E2P_SendData(wPos);
E2P_SendData(0xFFFF);
wTmp = E2P_ReadData();
break;

case E2P_WREN :
case E2P_WRDI :
E2P_SendCommand(bComando);
break;

}
/*Disable Slave Select line */
XMC_SPI_CH_DisableSlaveSelect(XMC_SPI1_CH1);

return wTmp;
}

 

//// Esegue una scrittura ed una lettura su Eeeprom alla locazione specificata e confronta i due valori
void E2P_Test()
{
uint16_t cellNum = 0; //32
uint16_t dataWr = 7;
uint16_t dataRd = 0;
static int flag = 0;

if(!flag){
E2P_WriteCell(cellNum, dataWr);
flag = 1;
}
else
{
dataRd = E2P_ReadCell(cellNum);
flag = 0;

if(dataRd == dataWr)
while(1);
}
}

 

main.c

#define CPU_RUN P2_3 //! Led CPU (debug purpose)

int main(void)
{
XMC_GPIO_SetMode(CPU_RUN, XMC_GPIO_MODE_OUTPUT_PUSH_PULL); /// Led CPU_RUN

SPI_Initialize();

SysTick_Config(SystemCoreClock / 1000);

while (1)
{
}
}

void SysTick_Handler()
{
static uint16_t tick = 0;
tick++;
if(5000 == tick)
{
E2P_Test();

tick = 0;
XMC_GPIO_ToggleOutput(CPU_RUN);
}
}

0 Likes
2 Replies
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @ChrisMarquesIta ,

In the data sheet of the CAT25640 it is mentioned that the data is shifted out on the falling edge of SCK out so make sure that while configuring the SPI config it should be Transmit at the rising edge and receive at the falling edge.
I have seen that you are using USIC1_CH1 and the MOSI,MISO.. pin configurations are correct.
So in order to assist you in a better way can you please attach your project.

Best Regards
Pradeep.

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi ,

Thread was locked due to inactivity for long time, you can continue the discussion on the topic by opening a new thread with reference to the locked one. 

 

Thanks and Regards,

Pradeep

0 Likes