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 use SPI function call from HalCoGen and manage external interrutp

Other Parts Discussed in Thread: TMS470MF06607

Hi,

I'm using a Hercules tms470MF06607 board.

I need to exchange data with an external board through SPI (CLK, SIMO,SOMI,SS) and manage an interrupt from GIOA[4].

I've used hlacogen to setup the project with what I need.

Now I'm looking at spi.h which has a lot of functions, but no documentation about how to use it.

Which one do I have to use?

If I choose for example

/** @fn uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint32 short *srcbuff)
*   @brief Transmits Data using polling method
*   @param[in] spi           - Spi module base address
*   @param[in] dataconfig_t    - Spi DAT1 register configuration
*   @param[in] blocksize    - number of data
*   @param[in] srcbuff        - Pointer to the source data ( 16 bit).
*
*   @return flag register value.
*
*   This function transmits blocksize number of data from source buffer using polling method.
*/
uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff)

I need to know the explanation of each field that belongs to spiDAT1_t which is a structure of this type

typedef struct spiDAT1RegConfig
{
    uint32 CS_HOLD;
    uint32 WDEL;
    uint32 DFSEL;
    uint32 CSNR;
}spiDAT1_t;

Is there any basic example about using SPI?

that means: bring low chip select, read/write some bytes through spi, bring up cs.

Another question is how and where the function that manages external interrupt is placed. I've connected the pin GIOA[4]. But how can I enable/disable interrupt handling? or clear the interrupt register once I've managed it from the function (and how can I setup the function? that means declare it and set it?)

Thanks

  • I've found that (maybe..) I have to put my code inside notification.c in the function gioNotification(sint32 bit).
    Does the bit parameter is the input who have triggered the interrupt, so if I have enabled GIOA[4] I should check if bit 1<<4 is 1?
    After I have managed the interrupt, is it ok to clear the interrupt doing this: GIOFLG1 |= 0x0f;

  • Looking at a demo video from TI, maybe I have figured out about reading and writing with SPI, like the following code
    for reading a single byte
    uint_8 rreg(BYTE reg)
    {
    uint_8 data;
    spiGetData(spiREG1,0,&data);
    return data;
    }

    for writing a single byte
    void wreg(BYTE reg)
    {
    spiSetData(spiREG1,0,reg);

    spiTransfer(spiREG1,0);

    while(!spiIsTransferComplete(spiREG1,0));
    }

    but I need to keep chip select active while writing multiple byte to an external chip, how can I do that?
    From HalcodeGen I can select the option "Chip select hold" on the transfer group. What does it means?
    Can I manually change the chip select like a GIO?

    Thanks
  • Enrico,
    Sorry for the delayed response. Glad you were able to get pretty far on your own.
    CSHOLD means that the chip select will remain active between two transfers without being deasserted.
    You can set CSHOLD for all the transfers except for the last, then on the last transfer when it is done the CS will be deasserted.
    This is potentially better than using the CS\ pin as a GPIO becuase the Mib unit can automatically manage the CSHOLD for you.
    For example if you use MibSPI there is a separate CSHOLD bit in each transmit buffer, so let's say you have a sequence where you want the transfer group to transfer 4 words with the CS low between the words but going high at the end, you can set CSHOLD in the first three transmit data registers but clear CSHOLD in the last.
    If you use the CPU to write to the SPI instead of using the Mib unit - you can also in a single write instruction (by using SPIDAT1) write new data and a new value for CSHOLD at the same time.