Hi,
I need a chip select output so that I can sync the SPI data stream with a MCP4922 DAC. The KE06Z seems to support a slave select output but I cannot make it work.
I am using the fsl_spi interface, and it turns out all the default master configuration is compatible with the DAC:
void SPI_MasterGetDefaultConfig(spi_master_config_t *config)
{
/* Initializes the configure structure to zero. */
memset(config, 0, sizeof(*config));
config->enableMaster = true;
config->enableStopInWaitMode = false;
config->polarity = kSPI_ClockPolarityActiveHigh;
config->phase = kSPI_ClockPhaseFirstEdge;
config->direction = kSPI_MsbFirst;
#if defined(FSL_FEATURE_SPI_16BIT_TRANSFERS) && FSL_FEATURE_SPI_16BIT_TRANSFERS
config->dataMode = kSPI_8BitMode;
#endif /* FSL_FEATURE_SPI_16BIT_TRANSFERS */
#if defined(FSL_FEATURE_SPI_HAS_FIFO) && FSL_FEATURE_SPI_HAS_FIFO
config->txWatermark = kSPI_TxFifoOneHalfEmpty;
config->rxWatermark = kSPI_RxFifoOneHalfFull;
#endif /* FSL_FEATURE_SPI_HAS_FIFO */
config->pinMode = kSPI_PinModeNormal;
config->outputMode = kSPI_SlaveSelectAutomaticOutput;
config->baudRate_Bps = 500000U;
}
I enabled the pin (PTE3) as a GPIO, not sure if this is correct, but I do not see any other way to route it.
My init in main() is:
SPI_MasterGetDefaultConfig(&masterConfig);
SPI_MasterInit(SPI_MASTER, &masterConfig, CLOCK_GetFreq(kCLOCK_BusClk));
While running my SPI output cycles (2 bytes using SPI_WriteBlocking()), I see clock and data but no signal on PTE3.
An I expected to manipulate MODFEN and SSOE directly? Very confused.
Thanks. I've already referred extensively to the example SPI code for KE06Z.
Having learned more, it seems that the hardware SPI module cannot do what I need anyway:
1) by using the API straightforwardly, the slave select output does not seem to operate (hence my post). This might be a misuse of the Pin configurator; I couldn't find a way to route that pin explicitly there.
2) even if slave select output did work, this gives me no way to synchronise my program with the actual transmission since there is no flag or interrupt that is timed to the frame, as far as I can see (the Tx Buffer empty flag can't be used for this afaics). (I need that synchronisation because I want to drive two distinct chip select outputs and also I want to drive a delay from the instant of chip deselect (while the DAC settles).)
3) Unlike other SPI libraries the SPI API doesn't seem to have any concept of transaction or sync (perhaps because the module doesn't either). "Blocking" mode relies only on the Tx Buffer empty flag (see above).
Instead I've implemented bitbanging and this solves the chip select sync problem completely.
If anyone who knows the chip or API well spots an error in the above, please reply with correction.
Hi @qu1j0t3 ,
The CS pin should work right after you select SPI function in SIM_PINSEL0 register. But if you have two DAC which need two CS, the SPI peripheral doesn't support it. You have to use GPIO to simulate two CS.
Regards,
Jing
CS did not work for me using the API.
Because the MCU does not seem to have any sync to framing, that could be used to time chip select lines, you can't use the onboard SPI module at if you have more than one slave but have to bit-bang all of SPI (which is not difficult).