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.

CC2538: CC2538 SPI slave mode problem ...

Part Number: CC2538

Hi,

I want to use the CC2538 SPI-0 port as slave interface. To try the SPI slave mode out, I have modified the provided SPI master example in the following way:

int
main(void)
{
    uint32_t pui32DataTx[NUM_SSI_DATA];
    uint32_t pui32DataRx[NUM_SSI_DATA];
    uint32_t ui32Index;

    //
    // Set the clocking to run directly from the external crystal/oscillator.
    // (no ext 32k osc, no internal osc)
    //
    SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);

    //
    // Set IO clock to the same as system clock
    //
    SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
   
    //
    // Set up the serial console to use for displaying messages.  This is
    // just for this example program and is not needed for SSI operation.
    //
    InitConsole();
    
    //
    // Display the setup on the console.
    //
    UARTprintf("SSI ->\n");
    UARTprintf("  Mode: SPI\n");
    UARTprintf("  Data: 8-bit\n\n");

    //
    // The SSI0 peripheral must be enabled for use.
    //
    SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_SSI0);

    //
    // Disable SSI function before configuring module
    //
    SSIDisable(SSI0_BASE);

    //
    // Set IO clock as SSI clock source
    //
    SSIClockSourceSet(SSI0_BASE, SSI_CLOCK_PIOSC);

    //
    // For this example SSI0 is used with PA2-PA5.  The actual port and pins
    // used may be different on your part, consult the data sheet for more
    // information.  GPIO port A needs to be enabled so these pins can be used.
    // TODO: change this to whichever GPIO port you are using.
    //
    // Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    //

    IOCPinConfigPeriphInput(EXAMPLE_GPIO_SSI_BASE, EXAMPLE_PIN_SSI_CLK,
                             IOC_CLK_SSI_SSI0);    

    IOCPinConfigPeriphInput(EXAMPLE_GPIO_SSI_BASE, EXAMPLE_PIN_SSI_FSS,
                             IOC_SSIFSSIN_SSI0);
    
    IOCPinConfigPeriphOutput(EXAMPLE_GPIO_SSI_BASE, EXAMPLE_PIN_SSI_TX,
                             IOC_MUX_OUT_SEL_SSI0_TXD);    
    
    IOCPinConfigPeriphInput(EXAMPLE_GPIO_SSI_BASE, EXAMPLE_PIN_SSI_RX,
                            IOC_SSIRXD_SSI0);    
    //
    // Configure the GPIO settings for the SSI pins.  This function also gives
    // control of these pins to the SSI hardware.  Consult the data sheet to
    // see which functions are allocated per pin.
    // The pins are assigned as follows:
    //      PA5 - SSI0Tx
    //      PA4 - SSI0Rx
    //      PA3 - SSI0Fss
    //      PA2 - SSI0CLK
    // TODO: change this to select the port/pin you are using.
    //
    GPIOPinTypeSSI(EXAMPLE_GPIO_SSI_BASE, EXAMPLE_PIN_SSI_CLK |
                   EXAMPLE_PIN_SSI_FSS | EXAMPLE_PIN_SSI_RX |
                   EXAMPLE_PIN_SSI_TX);
    GPIOPinTypeSSI(EXAMPLE_GPIO_SSI_BASE, EXAMPLE_PIN_SSI_CLK |
                   EXAMPLE_PIN_SSI_RX | EXAMPLE_PIN_SSI_TX);

    //
    // Configure SSI module to Motorola/Freescale SPI mode 3:
    // Polarity  = 1, SCK steady state is high
    // Phase     = 1, Data changed on first and captured on second clock edge
    // Word size = 8 bits
    //
    SSIConfigSetExpClk(SSI0_BASE, SysCtrlIOClockGet(), SSI_FRF_MOTO_MODE_3,
                       SSI_MODE_SLAVE, SysCtrlClockGet()/64, 8);
    
    //
    // Enable the SSI0 module.
    //
    SSIEnable(SSI0_BASE);

    //
    // Read any residual data from the SSI port.  This makes sure the receive
    // FIFOs are empty, so we don't read any unwanted junk.  This is done here
    // because the SPI SSI mode is full-duplex, which allows you to send and
    // receive at the same time.  The SSIDataGetNonBlocking function returns
    // "true" when data was returned, and "false" when no data was returned.
    // The "non-blocking" function checks if there is any data in the receive
    // FIFO and does not "hang" if there isn't.
    //
    while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0]))
    {
    }
    
    //
    // Receive indefinite.
    //
    while(1)
    {
        //
        // Receive the data using the "blocking" Get function. This function
        // will wait until there is data in the receive FIFO before returning.
        //
        SSIDataGet(SSI0_BASE, &pui32DataRx[0]);

        //
        // Since we are using 8-bit data, mask off the MSB.
        //
        pui32DataRx[0] &= 0x00FF;

        //
        // Display the data that SSI0 received.
        //
        UARTprintf("'%c' ", pui32DataRx[0]);
    }
...

I am not able to receive data as SPI slave. In master mode I can transmit and receive data.

I am aware that I have to use the correct pins (CLK is input, FSS is input MISO is output and MOSI is input). I have the connections made accordingly.

My impression is, that the pin multiplexing is incorrect. I do not get the master provided clock signal, there are no interrupts occurring.

Thank you for your help!

Frank