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.

SPI Driver using GPIO'S

Hi,

I allready used all SPI Ports on my Controller now i need one more, so i was thinking of writing a Driver using GPIO'S for this.

Has anybody done this before or is there a code example for C2000 Devices ?

cheers!

S.Fischer

 

 

  • Hi! 

    I have to use two SPI devices too! Have you got an example on how to do it using GPIOs?

    I would like to find a way to point a GPIO to the SPISTEA bit of the SPI protocol. Becouse it is like a ChipSelect, but I can't do it! Thanks!

  • Much easier to use multiple GPIO chip select lines and work each with the software than to do an SPI bus by bit-banging.

    This is done by assigning the SPI clock and data lines to their pins, but leave the SPI CS line as a GPIO output. Then when you want to access a device on the SPI bus, activate that devices' CS line, let the SPI peripheral do it's thing, then de-activate the devices CS line. This works for most SPI devices which allow and/or require the chip select to be constantly active during accesses. Only those few devices which use the CS as a frame select and expect the CS line to de-activate between bytes/frames etc cause a problem. Using multiple GPIO lines as chip selects also require some code to make sure you don't try and access two devices on the same SPI bus at the same time, but this is usually easy to do by using a single task to work the SPI bus, doing one operation at a time, and have other requesting tasks send an inter-task message, push an entry onto a FIFO, or other inter-task communication method with the operations to be done on the SPI bus.

  • Hi!

    I have tried to put low the GPIO61:

    Configuration:

     // GPIO61 is Output
    EALLOW;
    GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO61
    GpioCtrlRegs.GPBPUD.bit.GPIO61 = 0; // Pull up
    GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1; // Output
    EDIS;

    Use:

     
    GpioDataRegs.GPBDAT.bit.GPIO61 = 0; //chipselect low: receiving data
    SpiaRegs.SPITXBUF = 0x00; /* Send dummy data */
    while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1){} /* Wait for SPITXBUF is free */
    while (SpiaRegs.SPISTS.bit.INT_FLAG == 0){} /* Wait for RX to finish */
    x = SpiaRegs.SPIRXBUF; /* Read RXBUF */
    data_channelA1 = x;
    GpioDataRegs.GPBDAT.bit.GPIO61 = 1; //trasmission finished

    when I start the receive data istruction, but it goes up immedeately. How can I take low the GPIO voltage for the time of the communication?

    Have I to use timer? Please help me! Thanks!

  • I've found it is more reliable to use GPBCLR and GPBSET registers to write to GPIO output pins, and use GPBDAT just for reading what value is being output onto the pin.

  • Alessandro,

    Are you just looking use multiple SPI slave select lines?  If so, I provided an example in this recent post:

    http://e2e.ti.com/support/microcontrollers/tms320c2000_32-bit_real-time_mcus/f/171/t/171156.aspx#625809

    Check out the very last post and let me know if this is what you were looking for.

    Kris

  • Perefect! I will let you know as soon as I will proof!! Thank you!!

  • Thank you again Kris, your is a good example!