SPI master and 3 DAC's

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SPI master and 3 DAC's

980 Views
lah1
Contributor I

I have to attach 3 very similar DAC's to the same SPI interface and not knowing too much about SPI or the Kinetis K platform I thought I only had to make one SPI configuration, and then set the relevant chip select signals to switch between which DAC I was talking to. But from the questions/comments on the community it seems like I have to make 3 almost identical "master_config" with only the "whichPcs" being apart, and then re-initialize the specific SPI interface from scratch each time I need to switch DAC, is that really the case?

I would assume only one configuration was needed, and perhaps a specific function available to shift chip select.

I cannot find a good example for this to see how it's supposed to be done, can you perhaps point me to one?

I have the benefit of being able to use the newest MCUXpresso and SDK's available if needed. I am making code to be used on Kinetis K26_180, but I guess an example from any Kinetis board would help me, as I just need to understand how it's done. Perhaps even some documentation is available?

Labels (1)
Tags (1)
0 Kudos
Reply
3 Replies

754 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Lars,

i think one master_config is okay, when you want to transfer data to different slave spi modle, based on the driver example, you just use the following code.

You just change the EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER, it is okay.

 /*Start master transfer*/
    masterXfer.txData = masterTxData;
    masterXfer.rxData = masterRxData;
    masterXfer.dataSize = TRANSFER_SIZE;
    masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;

    DSPI_MasterTransferNonBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &g_m_handle, &masterXfer);

    /* Wait slave received all data. */
    while (!isTransferCompleted)
    {
    }

Hope it can help you

BR

xiangJun Rong

0 Kudos
Reply

754 Views
lah1
Contributor I

I'm sorry, but I don't think this answers my question: how do I do "Chip select" to select between my 3 SPI slaves?

Does your answer imply that I should not use the "whichPcs" variable in the SPI master control structure and do chip select with independent pins, or how is this supposed to work?

BR

Lars

0 Kudos
Reply

754 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Lars,

Anyway, if you can change handle->lastCommand or handle->command which are copied to base->PUSHR register when you transfer data, it is okay.

With the following lines, you can change the handle->lastCommand or handle->command.

/*Start master transfer*/
    masterXfer.txData = masterTxData;
    masterXfer.rxData = masterRxData;
    masterXfer.dataSize = TRANSFER_SIZE;
    masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;

 

    DSPI_MasterTransferNonBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &g_m_handle, &masterXfer);

 

    /* Wait slave received all data. */
    while (!isTransferCompleted)
    {
    }

In other words, if you want to select one DAC, just change the line:

masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;

then call the DSPI_MasterTransferNonBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &g_m_handle, &masterXfer);

the SPI will communicate with the device you selected by the EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER.

kDSPI_MasterPcs0 = 0U << DSPI_MASTER_PCS_SHIFT, /*!< DSPI master transfer use PCS0 signal. */
    kDSPI_MasterPcs1 = 1U << DSPI_MASTER_PCS_SHIFT, /*!< DSPI master transfer use PCS1 signal. */
    kDSPI_MasterPcs2 = 2U << DSPI_MASTER_PCS_SHIFT, /*!< DSPI master transfer use PCS2 signal.*/
    kDSPI_MasterPcs3 = 3U << DSPI_MASTER_PCS_SHIFT, /*!< DSPI master transfer use PCS3 signal. */
    kDSPI_MasterPcs4 = 4U << DSPI_MASTER_PCS_SHIFT, /*!< DSPI master transfer use PCS4 signal. */
    kDSPI_MasterPcs5 = 5U << DSPI_MASTER_PCS_SHIFT, /*!< DSPI master transfer use PCS5 signal. */

Pls have a try.

BR

xiangjun rong

0 Kudos
Reply