+ Reply to Thread
Results 1 to 3 of 3

Thread: XMC4500 SPI Slave

  1. #1
    New Member New Member akjain is on a distinguished road
    Join Date
    May 2018
    Posts
    2
    Points
    42.5

    XMC4500 SPI Slave

    Hi,

    I am trying currently to create a SPI Slave on a XMC4500 but somehow i cannot get it to work. This in part of an attempt to get DMA working with SPI. The sender (Master) side, I have already sucessfully programmed and it is running without a problem.

    Following is my code to configure the slave:

    Code:
    #define SPI_SLAVE_PIN_MISO P2_14
    #define SPI_SLAVE_PIN_MOSI P2_15
    #define SPI_SLAVE_PIN_SS   P0_6
    #define SPI_SLAVE_PIN_SCLK P0_11
    	
    #define SR_LINE_DMA_MASTER 0
    #define DMA_CHANEL_MASTER 1
    
    const uint16_t _blocksize = 1;
    const uint8_t sendData[_blocksize] = {0xAA};//, 0x02, 0x03, 0x04};
    uint8_t recvData[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    
    
    void USIC1_0_IRQHandler(void)
    {
    	//TODO cleanup
    	XMC_SPI_CH_ClearStatusFlag(XMC_SPI0_CH1, XMC_SPI_CH_EVENT_STANDARD_RECEIVE | XMC_SPI_CH_EVENT_ALTERNATIVE_RECEIVE);
    	return;
    }
    
    XMC_SPI_CH_CONFIG_t spi_config_slave =
    {
      .bus_mode = XMC_SPI_CH_BUS_MODE_SLAVE,
      .selo_inversion = XMC_SPI_CH_SLAVE_SEL_INV_TO_MSLS,
      .parity_mode = XMC_USIC_CH_PARITY_MODE_NONE
    };
    
    int main(void)
    {
    	XMC_SPI_CH_Init(XMC_USIC1_CH0, &spi_config_slave);	
    		
    	 XMC_SPI_CH_SetInputSource(XMC_USIC1_CH0,XMC_SPI_CH_INPUT_DIN0,USIC1_C0_DX0_P2_15);
    	 XMC_SPI_CH_SetInputSource(XMC_USIC1_CH0,XMC_SPI_CH_INPUT_SLAVE_SCLKIN,USIC1_C0_DX1_P0_11);
    	 XMC_SPI_CH_SetInputSource(XMC_USIC1_CH0,XMC_SPI_CH_INPUT_SLAVE_SELIN,USIC1_C0_DX2_P0_6);	
    
    		
    	 XMC_GPIO_SetMode(SPI_SLAVE_PIN_MOSI, XMC_GPIO_MODE_INPUT_TRISTATE);
    	 XMC_GPIO_SetMode(SPI_SLAVE_PIN_SS, XMC_GPIO_MODE_INPUT_TRISTATE);
    	 XMC_GPIO_SetMode(SPI_SLAVE_PIN_SCLK, XMC_GPIO_MODE_INPUT_TRISTATE);
    	 XMC_GPIO_SetMode(SPI_SLAVE_PIN_MISO, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2);
    
    	XMC_SPI_CH_EnableEvent(XMC_USIC1_CH0, XMC_SPI_CH_EVENT_STANDARD_RECEIVE);
    	XMC_SPI_CH_EnableEvent(XMC_USIC1_CH0, XMC_SPI_CH_EVENT_ALTERNATIVE_RECEIVE);
    	XMC_SPI_CH_EnableEvent(XMC_USIC1_CH0, XMC_SPI_CH_EVENT_RECEIVE_START);
    
    	XMC_SPI_CH_Start(XMC_USIC1_CH0);
    }
    btw: I am using the infineon Relax Kit with Keil DFP 2.10.0 for this example.

    Following Screen shows the signals which are being outputted on the SPI Channels by the SPI Master
    Click image for larger version

Name:	screen_spi.png
Views:	3
Size:	25.1 KB
ID:	3470

    Blue Signal: Slave Select singal from master -> P0.6
    Yellow Signal: CLK Signal -> P0.11
    Red Signal: MOSI Signal -> P2.15
    Green Signal: MISO Signal -> P2.14


    I have tried using the CMSIS Driver to implement a slave but also that was without any success. My long term goal is to also use DMA on the slave side to receive the data from the master.

    I hope somebody can help me with this matter.

    Thanks in advance
    Best Regards
    Last edited by akjain; May 22nd, 2018 at 04:21 AM.

  2. #2
    Advanced Advanced
    Infineon Employee
    Infineon Employee
    DRubeša will become famous soon enough
    Join Date
    Jul 2016
    Location
    München
    Posts
    193
    Points
    775.625
    Hi,

    I suggest you first to check the SPI_SLAVE_EXAMPLE_XMC4500 that is exactly written for your board and uses DMA mode which is also exactly what your application uses. What I can tell by a quick look is that you have issue in your interrupt service routine where you should clear the flag from "XMC_SPI1_CH0" module not "XMC_SPI0_CH1". However, this is a small thing and I guess the problem is that you´re not receiving anything from master. Take a look at the example, I´m sure you will find it beneficial.

    Regards,
    Deni
    The views expressed here are my personal opinions, have not been reviewed or authorized by Infineon and do not necessarily represent the views of Infineon.

  3. #3
    New Member New Member akjain is on a distinguished road
    Join Date
    May 2018
    Posts
    2
    Points
    42.5
    Hi Deni,

    I sat down yesterday and read the SPI Chapter again from the reference manual and found out my problem. I forgot to invert the CS singal on the slave side. Adding this one line to the code fixed the problem

    AndThanks for your quick answer and the link. It for sure seems interessting as a reference examples.

    Greetings
    adit

+ Reply to Thread

Tags for this Thread

Disclaimer

All content and materials on this site are provided “as is“. Infineon makes no warranties or representations with regard to this content and these materials of any kind, whether express or implied, including without limitation, warranties or representations of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, whether express or implied, is granted by Infineon. Use of the information on this site may require a license from a third party, or a license from Infineon.


Infineon accepts no liability for the content and materials on this site being accurate, complete or up- to-date or for the contents of external links. Infineon distances itself expressly from the contents of the linked pages, over the structure of which Infineon has no control.


Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Usage Terms of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Usage Terms of this site. Infineon reserves the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.