This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

external spi loopback on RM48 USB stick development kit

Other Parts Discussed in Thread: HALCOGEN

Hello,

I am attempting to set up an external loop back for the SPIs on the RM48 USB development kit/stick. I have found a handful of examples, and may have an idea of what's wrong but not too sure how to fix it.

I started with following the example_spi_Master_Slave.c in the HalCoGen tool. For the most part it's very helpful. However, I think my issue is that I only have access to SPICS1, and that is set up for CS0 of SPI1 to go to CS0 of SPI2. I thought it should be easy enough to change the chip select, however from messing with HalCoGen, it looks like I have to use the MIBSPI1 in order to have access to different chip selects. I then tried following the "example_mibspiDma.c" file, but then I am left confused trying to figure out how to send data using the MIBSPI functions and receive data using the SPI functions and vice versa. 

Any help trying to set up an external loopback from SPI1 to SPI2 on the USB stick would be greatly appreciated.

Thanks!

  • Andrew,

    I agree, I only see that you can use the CS[0] pin for the SPI driver.

    You need to do at least two things to make CS[1] used instead.  (There might be something I'm forgetting so I'm saying at least two).

    You probably also want to change the other spiREG->PC[x] registers like PC7 and PC8 which set the default pull to pullup...  you might get away without it but not sure.

    First, you need to go through the spiInit() function and change the initialization of the spiREGx->PCy registers.

    All of these will look something like:

        /** - SPI4 Port output values */
        spiREG4->PC3 =  1U        /* SCS[0U] */
                        | (0U << 8U)  /* ENA */
                        | (0U << 9U)  /* CLK */
                        | (0U << 10U)  /* SIMO */
                        | (0U << 11U); /* SOMI */

    And you will change them to something like this:

        /** - SPI4 Port output values */
        spiREG4->PC3 =  2U        /* SCS[1] */
                        | (0U << 8U)  /* ENA */
                        | (0U << 9U)  /* CLK */
                        | (0U << 10U)  /* SIMO */
                        | (0U << 11U); /* SOMI */

    In order to use CS[1] instead of CS[0].

    You should probably change all of the port control registers.    Just remember that on the slave SPI you want the CS port to be an input not an output...

    You can directly edit spiInit() to make the changes, but if you do so then if you generate from HalCoGen again you will need to make the changes again.

    So while not pretty, you can go to the end of the spiInit() function where the comment is for user code:


    /* USER CODE BEGIN (3) */
    /* USER CODE END */
    }

    And in this section add code that over-writes the generated code for the pin control pins.  This will result in writing to the pins twice which isn't necessary but it will be convenient for you since the code will survive through re-generation.

    Second, in the example code example_spi_Master_Slave.c, the chip select is set here:

     dataconfig1_t.CSNR    = 0xFE; (which is 1111 1110 or CS[0] is low)

    This is the pattern that you want to appear on the chip select lines when transmitting.

    To switch this to use CS[1] instead of CS[0],  change the code to :

     dataconfig1_t.CSNR    = 0xFD;  (which is 1111 1101 or CS[1] is low)

    There might be something I missed, but I hope this gets you started.

  • Sorry for the delay in responding.

    I'm surprised I missed the  dataconfig1_t.CSNR    = 0xFD;  (which is 1111 1101 or CS[1] is low). I think I was expecting that to be autogenerated and in spi.c - but it appears that was the only thing that was required for me to get the spi to work on the USB stick. Changing the Port output values actually seemed to have no affect. I'll have to look into it a little closer, but I suspect it's because on SPI2 I'm actually using CS0 (as that's what is available on J15 on the USB stick).

    I did notice that the example uses:

    /* Initiate SPI2 Transmit and Receive through Interrupt Mode */
    spiSendAndGetData(spiREG2, &dataconfig1_t, 16, TX_Data_Slave, RX_Data_Slave);

    and 

    	/* Initiate SPI1 Transmit and Receive through Polling Mode*/
    	spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, TX_Data_Master, RX_Data_Master);

    but for some reason there's no data on RX_data_slave until after I run the spiTransmitAndReceiveData function. I'll have to look into this further as well. 

     Thanks for the help

  • Andrew,

    Which SPI is your master again?   Remember that on SPI there is a master and a slave, and the master is the only one that can initiate the transfer by providing a clock.  I'd guess that SP1 is your master based on what you say you observe.

     

  • Anthony - 

    SPI1 is my master, you are correct.