xmc 4800 with xmxlib spi master and long frames

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

cross mob
Steffen_S
Level 1
Level 1
First solution authored First reply posted 5 sign-ins

hello, 

i use the XMC 4800 as SPI MAster and want to receive a frame with e.g. 200bytes. Do i have to call StartOfFrame and EndOfFrame? Word length is 16.

Here is how i do it at the moment:

 

 

//Init
XMC_SPI_CH_Init(pSPI1->pSpiChannel, &SPI_Channel_Config_30MHz);
	XMC_SPI_CH_SetBitOrderMsbFirst(pSPI1->pSpiChannel);
	XMC_SPI_CH_SetWordLength(pSPI1->pSpiChannel, (uint8_t)16);
	XMC_SPI_CH_SetFrameLength(pSPI1->pSpiChannel, (uint8_t)64);

	/* Configure the clock polarity and clock delay */
	XMC_SPI_CH_ConfigureShiftClockOutput(pSPI1->pSpiChannel, XMC_USIC_CH_BRG_SHIFT_CLOCK_PASSIVE_LEVEL_1_DELAY_DISABLED, XMC_SPI_CH_BRG_SHIFT_CLOCK_OUTPUT_SCLK);
	/* Configure Leading/Trailing delay */
	XMC_SPI_CH_SetSlaveSelectDelay(pSPI1->pSpiChannel, 2U);

	/* Configure the input pin properties */
	XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT4_BASE, (uint8_t)2, &SPI_MISO_Config.port_config);

	/* Configure the data input line selected */
	XMC_SPI_CH_SetInputSource(pSPI1->pSpiChannel, XMC_SPI_CH_INPUT_DIN0, (uint8_t)2);

	/* Start the SPI_Channel */
	XMC_SPI_CH_Start(pSPI1->pSpiChannel);

	/* Configure the output pin properties */
	XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT1_BASE, (uint8_t)9, &SPI_MOSI_Config.port_config);

	/* Configure the Slave Select pin properties, Storck */
	XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT1_BASE, (uint8_t)7, &SPI_SS_Config.port_config);

	XMC_SPI_CH_EnableSlaveSelect(pSPI1->pSpiChannel, XMC_SPI_CH_SLAVE_SELECT_2);

	/* Initialize SPI SCLK out pin */
	XMC_GPIO_Init((XMC_GPIO_PORT_t *)PORT1_BASE, (uint8_t)8, &SPI_SCLKOUT_Config.port_config);

	XMC_SPI_CH_ClearStatusFlag(pSPI1->pSpiChannel, XMC_SPI_CH_STATUS_FLAG_ALTERNATIVE_RECEIVE_INDICATION);
	XMC_SPI_CH_ClearStatusFlag(pSPI1->pSpiChannel, XMC_SPI_CH_STATUS_FLAG_RECEIVE_INDICATION);

	XMC_USIC_CH_SetInterruptNodePointer(pSPI1->pSpiChannel, XMC_USIC_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE, (uint32_t)3);
	XMC_USIC_CH_SetInterruptNodePointer(pSPI1->pSpiChannel, XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE, (uint32_t)3);
	XMC_USIC_CH_SetInterruptNodePointer(pSPI1->pSpiChannel, XMC_USIC_CH_INTERRUPT_NODE_POINTER_PROTOCOL, (uint32_t)5);
	XMC_USIC_CH_SetInterruptNodePointer(pSPI1->pSpiChannel, XMC_USIC_CH_INTERRUPT_NODE_POINTER_TRANSMIT_BUFFER, (uint32_t)4);

	/* Set priority of the Transmit interrupt */
	NVIC_SetPriority((IRQn_Type)94, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 9U, 0U));

	/* Enable Transmit interrupt */
	NVIC_EnableIRQ((IRQn_Type)94);

	/* Set priority of the Receive interrupt */
	NVIC_SetPriority((IRQn_Type)93, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 8U, 0U));

	/* Enable Receive interrupt */
	NVIC_EnableIRQ((IRQn_Type)93);

 

 

   and then my StartReceive Function:

 

 

 

	/* Clear RBF0 */
	(void)XMC_SPI_CH_GetReceivedData(pthis->pSpiChannel);
	/* Clear RBF1 */
	(void)XMC_SPI_CH_GetReceivedData(pthis->pSpiChannel);


XMC_USIC_CH_EnableEvent(pthis->pSpiChannel, (uint32_t)((uint32_t)XMC_USIC_CH_EVENT_STANDARD_RECEIVE | (uint32_t)XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE));

// Send 200 bytes
XMC_USIC_CH_EnableEvent(pthis->pSpiChannel, (uint32_t)XMC_USIC_CH_EVENT_TRANSMIT_BUFFER);
	XMC_SPI_CH_SetTransmitMode(pthis->pSpiChannel, XMC_SPI_CH_MODE_STANDARD);
	XMC_USIC_CH_TriggerServiceRequest(pthis->pSpiChannel, pthis->SPI_ServiceRequest_ID);

 

 

 

In the Transmit_ISR i am writing 16 bit to the buffer until 200 bytes are transferred.

 

Do i have to Use StartOfFrame and EndOfFrame in my Use Case? If So, i would Call StartOfFrame before the first 16 bit are send and call EndOfFrame after 199 Words are sent. Is that correct? Will this help me? Am I doing it not correct at the moment? What benefits to do i get from using SoF and EoF?

 

Thank you in advance and regards,

steffen

Steffen

0 Likes
1 Solution
Steffen_S
Level 1
Level 1
First solution authored First reply posted 5 sign-ins

thank you for your response 🙂 in general, what are the benefits from controlling frame start and frame end by software instead of hardware? right now, all i do is enable slave select, write my data to buftci untill all dummy data is sent and all words received. after that, i disable slave select. it appears to work. 🙂

View solution in original post

0 Likes
3 Replies
ncbs
Moderator
Moderator
Moderator
500 replies posted 50 likes received 250 sign-ins

Hi @Steffen_S ,

The following thread might interest you: https://community.infineon.com/t5/XMC/SPI-frame/td-p/301386

Refer to section 2.3.1 of AP32303 - Universal Serial Interface Channel (USIC) for internal working of SPI master data transmission process.

Regards,
Nikhil

0 Likes
Steffen_S
Level 1
Level 1
First solution authored First reply posted 5 sign-ins

thank you for your response 🙂 in general, what are the benefits from controlling frame start and frame end by software instead of hardware? right now, all i do is enable slave select, write my data to buftci untill all dummy data is sent and all words received. after that, i disable slave select. it appears to work. 🙂

0 Likes
Aashita_R
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi @Steffen_S,

 Answering your query, Hardware flow control uses extra wires, where the logic level on these wires define whether the transmitter should keep sending data or stop. With software flow control, special characters are sent over the normal data lines to start or stop the transmission. Hence, hardware reduction is one such advantage with software flow control. Also, flow control is totally based on application level protocol on at what speed is the frame for start/stop controlled depending on your use case.

Best Regards,

Aashita

0 Likes