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.

How to us HET pins as GPIO?

Other Parts Discussed in Thread: HALCOGEN

Hello,

I have to say that these TI forums are most excellent!  Response has been very quick and useful.

Ok, onto my question.  I have a TMS570LS0432PZ that I have used all the GPIOA lines on and I need more.  I had connected up some external parts to the N2HET pins (19, 22, 25, 26, 90, 97, 98, 11, 64) t.  How do I control them?  Halcogen seems to have HET1 controls, am I done for?

I also want to bit bang the SPI1, SPI2 and SPI3 lines for now, can I do that?

Example code would be most appreciated, but I can understand if there isn't anything available.  General instructions would be fine, I'll muddle through them.

Thanks!

--Tom V.

  • Tom,

    The GIO module, HET and SPI/MIBSPI have the same registers set to control their pins when not used as functional mode.

    In Halcogen, you just have to enable the GIO driver. This will create all APIs to control GIO functions for GIO, HET and SPI/MIBSPI.

    If you want to use HET and control some of HET pins as GIO, just include in your code the reg_het.h.
    (For SPI, reg_spi.h , for MIBSPI, reg_mibspi.h and for GIO, reg_gio.h

    This will define:

    spiPORT1, spiPORT2, spiPORT3... depending on how many SPI are available on the selected device.
    mibspiPORT1, mibspiPORT3, mibspiPORT5 depending on how many MIBSPI are available on the selected device.
    hetPORT1, hetPORT2 depending on how many HET are available on the selected device.
    gioPORTA, gioPORTA... depending on how many GIO port are available on the selected device.

    Now in all GIO APIs use this definition as first argument.

    Example:

        gioSetDirection(hetPORT1, 0xFFFFFFFF);

    This will configure all HET1 pins as output.

    When GIO APIs are used for GIO module, it is necessary first to call gioInit(). Depending on the setup defined in Halcogen, you can already define which pins are IN or OUT, the level, and even if pullup or pulldown are necessary (for input)

    When GIO APIs are used for HET module, there is no need to call hetInit(). So all configuration (IN, Out, Pull....) have to be done via the GIO APIs.

    When GIO APIs are used for SPI/MIBSPI, there is no need to call spiInit(), but it is necessary to force the module out of reset.
    This can be done as following:

        /** bring SPI1 out of reset */
        spiREG1->GCR0 = 0U;
        spiREG1->GCR0 = 1U;

        /** bring SPI2 out of reset */
        spiREG2->GCR0 = 0U;
        spiREG2->GCR0 = 1U;

        /** bring MIBSPI1 out of reset */
        mibspiREG1->GCR0 = 0U;
        mibspiREG1->GCR0 = 1U;

    Please let me know if I've answered your question.

  • Hi Jean-Marc,

    I got the HET I/O pins to work beautifully, but no luck with the SPI I/O pins.

    Some dumb questions:

    1) How do I know which I/O port bits correspond to which SPI pins?  I would like to try just bit banging the SPI initially, just to make sure the device on the other end works correctly.

    2)  Do I need to set the port direction bits?  Right now I'm just getting the SPI port out of reset and then trying to toggle the I/O pins, is there any other set up that I need to do?  I'm not seeing anything moving on the scope, the pins just stay high.

    3) Could it be that I have the SPI port setup in Halcogen?  Should I disable the SPI drivers/ports

    Any pointers would be greatly appreciated.

  • Thomas,

    1] In spi,h there is an enumeration for all SPI pins as shown below:

    enum spiPinSelect
    {
        SPI_PIN_CS0    = 0U,
        SPI_PIN_CS1    = 1U,
        SPI_PIN_CS2    = 2U,
        SPI_PIN_CS3    = 3U,
        SPI_PIN_CS4    = 4U,
        SPI_PIN_CS5    = 5U,
        SPI_PIN_CS6    = 6U,
        SPI_PIN_CS7    = 7U,
        SPI_PIN_ENA    = 8U,
        SPI_PIN_CLK    = 9U,
        SPI_PIN_SIMO   = 10U,
        SPI_PIN_SOMI   = 11U,
        SPI_PIN_SIMO_1 = 17U,
        SPI_PIN_SIMO_2 = 18U,
        SPI_PIN_SIMO_3 = 19U,
        SPI_PIN_SIMO_4 = 20U,
        SPI_PIN_SIMO_5 = 21U,
        SPI_PIN_SIMO_6 = 22U,
        SPI_PIN_SIMO_7 = 23U,
        SPI_PIN_SOMI_1 = 25U,
        SPI_PIN_SOMI_2 = 26U,
        SPI_PIN_SOMI_3 = 27U,
        SPI_PIN_SOMI_4 = 28U,
        SPI_PIN_SOMI_5 = 29U,
        SPI_PIN_SOMI_6 = 30U,
        SPI_PIN_SOMI_7 = 31U
    };

    This is matching the SPI Register specification: (Example for the DIR Register)

    For example, the void gioSetBit(gioPORT_t *port, uint32 bit, uint32 value) API expects a bit position (0 to 31)  and a value (0 or 1)

    gioSetBit(spiPORT1, SPI_PIN_CLK ,1); 

    This will set to 1 the SPI1_CLK pin.

    2] Yes if you want to output on a pin a 1 or 0, the pin direction has to be set as output. The input register will always reflects the state of the pin, whatever it is In or Out.

    If you enable the SPI driver generation in Halcogen, by default, during SPIINIT(), the SPI pins are default to functional mode (SPI mode)
    In this mode, the SPISET, SPICLR, SPIOUT will not have any effect.
    Now, in Halcogen SPIx Port tab, you can change this default SPI function to GIO mode. This tab will also provide all configuration for Direction, State, Pull, Driver type...) as shown below:

    In this display, all SPI pins are in Functional mode (SPI)

    If you want to use that way to setup the default state for SPI pins, than you have to enable SPI driver generation, and in your main, you have to call the spiinit().

    After that, you can use any GIO APIs to control your SPI pins.

  • Hi Jean-Marc,

    Thanks so much for the speedy reply!

    I set up the pins for GIO connections and set the necessary direction bits to be output in Halcogen and wrote the following very small program.  Sadly it does not work. the SPI CS lines all just stay high.  Any pointers would be greatly appreciated.  I'm sure it is something stupid.  I looked all over the code for clues as to why it is not working, but I'm not seeing anything obvious.  I'm watching pins 73, 93 and 27 on the processor

    #include "sys_common.h"
    #include "reg_het.h"
    #include "reg_spi.h"
    #include "reg_gio.h"
    #include "spi.h"
    #include "gio.h"

    void main(void)
    {
      volatile unsigned int i,j;

      spiInit();  /* tried with and without - no difference */


      gioSetDirection(spiPORT1,
              (1<<SPI_PIN_CS0) |
              (1<<SPI_PIN_CS1) |
              (1<<SPI_PIN_CS2) |
              (1<<SPI_PIN_CS3) |
              (1<<SPI_PIN_ENA) |
              (1<<SPI_PIN_CLK) |
              (1<<SPI_PIN_SIMO)
      );

      /** bring SPI1 out of reset */
      spiREG1->GCR0 = 0U;
      spiREG1->GCR0 = 1U;

      gioSetBit(spiPORT1, SPI_PIN_CS0, 1);
      gioSetBit(spiPORT1, SPI_PIN_CS1, 1);
      gioSetBit(spiPORT1, SPI_PIN_CS2, 1);
      gioSetBit(spiPORT1, SPI_PIN_CS3, 1);

      for(;;)
      {

        gioSetBit(spiPORT1, SPI_PIN_CS0, 0);


        for (i=0; i<0x3FFFFF; i++)j = i;
        gioSetBit(spiPORT1, SPI_PIN_CS0, 1);
        gioSetBit(spiPORT1, SPI_PIN_CS1, 0);

        for (i=0; i<0x3FFFFF; i++)j = i;
        gioSetBit(spiPORT1, SPI_PIN_CS1, 1);
        gioSetBit(spiPORT1, SPI_PIN_CS2, 0);

        for (i=0; i<0x3FFFFF; i++)j = i;
        gioSetBit(spiPORT1, SPI _PIN_CS2, 1);

      }

      /* USER CODE END */
    }

  • Thomas,

    I may have not be clear enough.

    Many peripheral modules have a reset bit in their control register.
    Out of power on Reset, peripheral modules are in reset condition, and depending on the application, only the one in use are forced out of reset.

    The xxxinit() API is doing this for you. First the module is released from reset and than the module configuration is done.

    In your code, you call in the beginning of main, spiInit();  This is ok, and depending on your Halcogen configuration for SPI1 (in this specific case) the module is configured and ready.

    Next you use

    gioSetDirection(spiPORT1,
              (1<<SPI_PIN_CS0) |
              (1<<SPI_PIN_CS1) |
              (1<<SPI_PIN_CS2) |
              (1<<SPI_PIN_CS3) |
              (1<<SPI_PIN_ENA) |
              (1<<SPI_PIN_CLK) |
              (1<<SPI_PIN_SIMO)
      );

    This will make all specified pin as output. (assuming that in Halcogen SPI1 Port tab you have selected GIO instead of SPI for all these pins)

    The next step is the problem.

      /** bring SPI1 out of reset */
      spiREG1->GCR0 = 0U;
      spiREG1->GCR0 = 1U;

    This will reset SPI1. All previous configuration are lost. The rest of the code is no more working, SPI1 Direction is back to input.

    To fix the problem, you have 2 options.

    1] Remove

      /** bring SPI1 out of reset */
      spiREG1->GCR0 = 0U;
      spiREG1->GCR0 = 1U;

    2] Move

      /** bring SPI1 out of reset */
      spiREG1->GCR0 = 0U;
      spiREG1->GCR0 = 1U;

    In place of

    spiInit();  /* tried with and without - no difference */

    Please make a try and let me know.

  • Thomas,

    What is the status on this thread?
    Did I answered your question?
  • I apologize for not responding sooner.  Yes, questions have been answered. 

    Thank you so much!

    -Tom