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.

LAUNCHXL2-RM57L: Using spi and gpio pins simultaneously (spi1(simo,somi,clk,scs[0]) as slave and spiscs[1],spiscs[2],spiscs[3],spiscs[4],spiscs[5]],spi1en as gio pins.

Part Number: LAUNCHXL2-RM57L
Other Parts Discussed in Thread: HALCOGEN

I am trying to use some pins of the SPI1 port as spi  and gpio at the same time.

I generated the code through halcogen. below is my code.

//CONFIGURE FOR GIO AND SPI

/* SPI1 set all pins to functional */
spiREG1->PC0 = (uint32)((uint32)1U << 0U) /* SCS[0] */
| (uint32)((uint32)0U << 1U) /* SCS[1] */| (uint32)((uint32)0U << 2U) /* SCS[2] */| (uint32)((uint32)0U << 3U) /* SCS[3] */| (uint32)((uint32)0U << 4U) /* SCS[4] */| (uint32)((uint32)0U << 5U) /* SCS[5] */| (uint32)((uint32)0U << 8U) /* ENA */| (uint32)((uint32)1U << 9U) /* CLK */| (uint32)((uint32)1U << 10U) /* SIMO[0] */| (uint32)((uint32)1U << 11U) /* SOMI[0] */| (uint32)((uint32)0U << 17U) /* SIMO[1] */| (uint32)((uint32)0U << 25U); /* SOMI[1] */

//CONFIGURE GIO AS OUTPUT PINS

/** - SPI1 Port direction */
spiREG1->PC1 = (uint32)((uint32)1U << 0U) /* SCS[0] */ (uint32)((uint32)1U << 1U) /* SCS[1] */| (uint32)((uint32)1U << 2U) /* SCS[2] */| (uint32)((uint32)1U << 3U) /* SCS[3] */| (uint32)((uint32)1U << 4U) /* SCS[4] */
| (uint32)((uint32)1U << 5U) /* SCS[5] */| (uint32)((uint32)1U << 8U) /* ENA */| (uint32)((uint32)1U << 9U) /* CLK */| (uint32)((uint32)1U << 10U) /* SIMO[0] */| (uint32)((uint32)0U << 11U) /* SOMI[0] */| (uint32)((uint32)1U << 17U) /* SIMO[1] */| (uint32)((uint32)0U << 25U); /* SOMI[1] */

but i am not sure how to program the bits i configured as output using the below function ?( i want to put SCS[1]=1,SCS[2]=1,SCS[3]=1, ENA =0,SOMI[1]=1; how do i do this?

gioSetBit(spiPORT1,0,1);

  • Hi Kalyan,
    You would use gioSetDirection() API to change direction of the port. For example if you want to set the SCS[5:0] to GIO output you will write gioSetDirection(spiPORT1, 0x3F);
  • ok i could set the bits using SPIPC4 REG thankyou.
    I have one more question

    What is the max spi clock frequency i can operate RM57lx as a slave ?
    the actual baudrate changes when i set the baudrate to 10mhz.

    If i configure SPI1SCS[1] as input how do i enable an interrupt for it?(how to enable gio interrupt on spi ports)

    i could configure the gio port A as falling or rising edge but couldn't find how to configure SPI Port1(GIO) Interrupt
  • Hi,

    1. Per the datasheet the slave mode can work up to 25MHz.
    2. The actual baudrate will depend on the source clock (VCLK) to the SPI module. When you specify 10MHz the actual baud rate in HalcoGen may show 9.375MHz as the closest baudrate if the VCLK=75MHz.
    3. You can use SPI pins in GIO mode for interrupt. This is not supported. If you want GIO interrupt capable pins, you need to look at the GIO module where both ports are interrupt capable.
  • Thankyou
    I am trying to use rm57l8 spi 1 port as slave.
    I want to generate an interrupt when( data is received in rx buffer or when rx is overran RXINT,RXOVRNINT)

    i am trying to find which function registers the handler to be called when an SPI interrupt(RXINT,RXOVRNINT) occurs?
  • Hi Kalyan,

     I'm not clear on your question as to what function registers to call. Do you have problem to generate interrupts for RXINT and RXOVRNINT?

     First of all, you need to make sure the RXINT and OVRINIT interrupts are enabled. In HalCoGen you can enable them like below.

    There are two levels of interrupt; High level and Low level. By default the SPI interrupts are mapped to High level as shown in the above configuration. You need to also enable MibSPI1 High level interrupt in the VIM channel 12 like below. 

    Once you slave receives the data or in the even that the data is overwritten (overrun error), it will generate an interrupt. 

  • I followed these steps and still some reason i am not able to see the interrupt when  my master sends the data.

    I want to make one thing sure how does the cpu know to trigger this function(mibspi1HighLevelInterrupt) when an interrupt occurs.

    I need to declare some where in the main.c program right?

  • Did you enable the interrupt for the CPU? If you place a breakpoint at 0x18 and if the CPU never halt then most likely the IRQ interrupt is not enabled. Also check the RXINT and OVRINIT flags in the SPI module whether or not they are set.

    In your main you can call _enable_IRQ_interrupt_()/_enable_interrupt_() to enable the interrupt.


    ;-------------------------------------------------------------------------------
    ; Enable interrupts - CPU IRQ

    .def _enable_IRQ_interrupt_
    .asmfunc

    _enable_IRQ_interrupt_

    cpsie i
    bx lr

    .endasmfunc
    ;-------------------------------------------------------------------------------
    ; Enable interrupts - CPU IRQ & FIQ

    .def _enable_interrupt_
    .asmfunc

    _enable_interrupt_

    cpsie if
    bx lr

    .endasmfunc
  • i couldnt get the interrupt working

    i am using spi3 as master and spi2 as slave.

    and this is the code i have in main.

    i have attached my whole project.

    I couldnt find any example code for spi using rm57lx

    int main(void)

    {

    /* USER CODE BEGIN (3) */

    spiDAT1_t dataconfig1_t;

    dataconfig1_t.CS_HOLD=FALSE;

    dataconfig1_t.WDEL=TRUE;

    dataconfig1_t.DFSEL=SPI_FMT_1;

    dataconfig1_t.CSNR=0XFE;

    /*eNABLE CPU INTERRUPT THROUGH cpsr */

    //_enable_IRQ();

       /** bring SPI out of reset */

       spiREG1->GCR0 = 1U;

       /** bring GIO module out of reset */

       gioREG->GCR0      = 1U;

       gioInit();

       spiInit();https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/312/2555.SPI1_5F00_SLAVE.7z

       _enable_IRQ_interrupt_();

       spiTransmitData(spiREG3,&dataconfig1_t ,BUFFERSTOWRITE,g_TransmitBuf);

    /* USER CODE END */

       return 0;

    }

  • Can you please send the halcogen .dll and .hcg files? I like to take a look.

    Below is an example I found for another device but it should serve as an guide for you.

    /* USER CODE BEGIN (2) */
    uint16 TX_Data_Master[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 };
    uint16 RX_Data_Master[16] = { 0 };
    uint16 done=0;
    /* USER CODE END */

    void main(void)
    {
    /* USER CODE BEGIN (3) */
    uint32 counter=0;
    spiDAT1_t dataconfig1_t;

    dataconfig1_t.CS_HOLD = FALSE;
    dataconfig1_t.WDEL = TRUE;
    dataconfig1_t.DFSEL = SPI_FMT_0;
    dataconfig1_t.CSNR = 0xFE;


    /* Enable CPU Interrupt through CPSR */
    _enable_IRQ();
    printf("IRQ interrupt are now enabled\n");
    spiInit();
    printf("SPI2 is now initialized\n");
    spiEnableLoopback(spiREG2,Analog_Lbk);
    printf("SPI is setup in loopback mode (Analog)\n");
    /* Initiate SPI2 Transmit and Receive through Interrupt Mode */
    spiSendAndGetData(spiREG2, &dataconfig1_t, 16, TX_Data_Master,RX_Data_Master);
    printf("TX_Data_Master has been sent out and should be received in RX_Data_Master\n");
    while(done==0)
    {
    counter++;
    }
    printf("buffer has been successfully sent\n");
    while(1);
    /* USER CODE END */
    }

    In the notification.c there is the below code.


    /* USER CODE BEGIN (8) */
    extern uint16 done;
    /* USER CODE END */

    #pragma WEAK(spiNotification)
    void spiNotification(spiBASE_t *spi, uint32 flags)
    {
    /* enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (31) */
    /* USER CODE END */
    }

    /* USER CODE BEGIN (32) */
    /* USER CODE END */
    #pragma WEAK(spiEndNotification)
    void spiEndNotification(spiBASE_t *spi)
    {
    /* enter user code between the USER CODE BEGIN and USER CODE END. */
    /* USER CODE BEGIN (33) */
    done=1;
    /* USER CODE END */
    }
  • https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/312/2664.SPI1_5F00_SLAVE.7zI am not using the loopback mode.

    I am externally connecting spi3(master) to spi2(slaves)

    here  is my halcogen project

  • Looking at your halcogen setting for SPI3 I don't see you enable TXINT interrupt. In your VIM, you did not enable MibSPI3 in either channel 37 or 38 either.

  • i am using spi3 as master and i am sending data using polling method .I could see my spi3 (data,clock and cs ) on oscope and they are correct.
    but my spi2 which is a slave doesn't receive this data .
    i connect spi3 to spi2 with wires .
  • Hi Charles,

    Can you please provide me with a example code for spi slave using rm57lx?

    I couldn't find any thing online.

  • Hi.

     Here is one simple example that you can reference. It setup SPI1 and SPI3 for communication.

    6518.LC4357_SPI1_SPI3_No_DMA.zip