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.

TI-rtos SPI question

Other Parts Discussed in Thread: TM4C1294NCPDT

Hi All:

Now my board use TM4C1294ncpdt and connect a Macronix MX25L6406E serial flash via SSI2,
development environment is TI-rtos & NDK.
I've tested 2 sample code find in the e2e.

1.
e2e.ti.com/.../1145.TM4C129_5F00_SSI3_5F00_MacronixFlash.7z
This file used SSI3 and tivaware code, after I modify to SSI2, this program can work normally.

2.
processors.wiki.ti.com/.../TI-RTOS_Examples_SerialFlash
This code used TI-RTOS & SSI2 interface, When I try to modify to MX25L6406E command, this program can't work. I can find CS, SCLK and
MOSI signal, but can't find SIMO signal via Oscilloscope.

I'm confused about two point about TI-RTOS_Examples_SerialFlash project. Below is my partial code.

unsigned char MX6406E_readREMS(AT45DB_Handle handle)
{
    SPI_Transaction spiTransaction;
    unsigned char txBuffer[5];
    volatile unsigned char status[5];
    IArg key;

    /* Initialize master SPI transaction structure */

    txBuffer[0]=0x90;
    txBuffer[1]=0x0;
    txBuffer[2]=0x0;
    txBuffer[3]=0x0;

    spiTransaction.count = 4;
    spiTransaction.txBuf = txBuffer;
    spiTransaction.rxBuf = NULL;

    key = GateMutex_enter(GateMutex_handle(&(handle->gate)));

    /* Initiate SPI transfer */
    GPIO_write(handle->gpioCS, PIN_LOW);

    if (!SPI_transfer(handle->spiHandle, &spiTransaction)) {

        Log_print1(Diags_USER1, "Unsuccessful SPI opcode transfer", NULL);
        System_printf("Unsuccessful SPI opcode transfer");
    }

    status[0]=1;
    status[1]=1;
    /* Get status */
    spiTransaction.count = 2;
    spiTransaction.txBuf = NULL;
    spiTransaction.rxBuf = (Ptr)&status;

    if (!SPI_transfer(handle->spiHandle, &spiTransaction)) {

        Log_print1(Diags_USER1, "Unsuccessful SPI data transfer", NULL);
        System_printf("Unsuccessful SPI data transfer");
    }

    System_printf("Joey recv (%d %d)", status[0],  status[1]);
    System_flush();

    GPIO_write(handle->gpioCS, PIN_HIGH);

    GateMutex_leave(GateMutex_handle(&(handle->gate)), key);

    return (status);
}


a. The code used three SPI_transfer, I think one is for MOSI, other is for SIMO, I'm not sure that's a right method to transfer SPI?
b. Sample code use
GPIO_write(handle->gpioCS, PIN_LOW);
GPIO_write(handle->gpioCS, PIN_HIGH);

Why I need set this GPIO?
c. Why I can't get SIMO signal, and can you give me some suggestions to modify the program?

I don't have more experience to control SPI via TI-rtos and hope you can give me some suggestions.
Thank you very much!

Best Regards,
Joey

  • The SPI driver abstracts out the need to play with the MOSI, SIMO, etc. The first transfer tells the SPI Flash device that a read command is coming. The second transfer is the read. Note: both a read and write can occur in a transfer (thus the rx and tx buffer). The GPIO write in the original example was used to write the chip select. That's why it was done at the start and end of the transfers. You need to look at your SPI flash device to see what is required for the chip select.

    Did you update the "board.c" to use SSI2 and the required chip select?

    Todd

  • Hi Todd:

    Thanks for you response.

    1. You are right. I also see the codes that "both a read and write can occur in a transfer".
    So how do you know when to use one SPI_Transfer or two SPI_Transfer for separate write and receive command?
    Just try & error, or serial flash datasheet will say that?

    2. I don't have many experiences about SPI, I think fss and chip select are the same meaning. In EK_TM4C1294XL.c
    have these configure,

    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);

    GPIOPinConfigure(GPIO_PD3_SSI2CLK);
    GPIOPinConfigure(GPIO_PD2_SSI2FSS);
    GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
    GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);

    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 |
    GPIO_PIN_2 | GPIO_PIN_3);

    but gpioCS is define as below
    /* EK_TM4C1294XL_CS */
    GPIOTiva_PC_7 | GPIO_CFG_OUT_STD | GPIO_CFG_OUT_STR_HIGH | GPIO_CFG_OUT_HIGH,

    I'm confused why FSS and CS pin are different? Or I have some mistakes?

    3. I don't update SSI2 chip select because my SPI wire design is follow default schematic.

    Joey
  • Joey Yang said:
    So how do you know when to use one SPI_Transfer or two SPI_Transfer for separate write and receive command?
    Just try & error, or serial flash datasheet will say that?

    Serial flash datasheet

    Joey Yang said:
    2. I don't have many experiences about SPI, I think fss and chip select are the same meaning. In EK_TM4C1294XL.c
    have these configure,

    The Tiva SSI peripheral has some cool features that other TI MCUs do not. Yes, you can use the FSS for the chip select. We wrote the AT45DB module to use an explicit chip select so it could be used on different TI MCUs. You can use the FSS instead and change the AT45DB to not do the chip select calls. Please note, we have not tested this with the AT45DB code.

    Todd