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 quick start

Other Parts Discussed in Thread: DAC7568, HALCOGEN, TMS570LS3137

Hi,

I'm starting using SPI on my Hercules HDK but have some problems. Where can I found a simple example? I need only to send 16bit commands to my device (a TI DAC7568). The protocol requires only 3 cables (clock, data and another one called sync which, requiring only to stay low during transmission, I suppose can be performed by the CS signal.

Seems that in halcogen there's not a lot to do: enabling SPI2 driver and selecting LSB first for my protocol (required by the device).

Do this code is enough?

    spiInit();

    spiDAT1_t dataconfig; // How to fill this?

    // build command
    uint16 data[2];

    data[0]=...
    data[1]=...

    spiTransmitData(spiREG2, &dataconfig,2,data);

What must be set in the dataconfig struct? (Ive found no description about).

Where I can select to use the "Data format 0" I've setup in Halcogen?

Do I forgot something?

Thank you

  • Matteo,

    I did for another customer a basic SPI test code that demonstrate usage of Halcogen driver in polling and interrupt mode.

    This code is running on TMS570LS3137 hdk and needs external connection between SPI2 and SPI3.

    You can have a look to the Halcogen config and the sys_main.c

    Please let me know if this is helpful.

    3007.SPI_Master_Slave_Demo.zip

  • Matteo,

    There is an example code example_SPI_Master_Slave.c that comes with HalCoGen that should be your starting point.

    It will show you the dataconfig structure.

    In the user guide, please look at the SPIDAT1 register.  If you are using multiple data formats and want to switch between them you can write 32-bit data to this register  (as opposed to writing the 16-bit SPI data to SPIDAT0).

    When you write to SPIDAT1 you not only write the data, but you also tell the SPI which data format to use,  which chip select number, and a few options for wait states.   This way you can have up to 4 SPI formats supported simultaneously and depending on which slave you are talking to on the SPI bus,  pick the correct format and chip select for that slave by appending the information into the data word.   This means also that you can talk to different slaves and diffferent chip selects with DMA - without reprogramming the SPI between devices.

    That's the 'why' behind the feature.  You could also just leave the default there for chip select and format and write only new data to SPIDAT0.   This you might do if you only have one slave device and are only using one chip select.

     

  • Now It works.Thank you.