RICCARDO MAESTRI

K82 SPI port - unable to set CS as "active low"

Discussion created by RICCARDO MAESTRI on Nov 8, 2017
Latest reply on Nov 10, 2017 by xiangjun.rong

Hi all,

i have a working SPI bus through two devices. The master is a K82, i'm developing on MCUXPRESSO.

 

To get it work I have disabled the chip select pin, to keep it low. Fast way is setting the driver to use CS0 that is an unused pin. I'm forced to do that because even if I set CS4 on the driver configuration to work as "active low" it still goes high when the communication starts.

 

This is part of the code involved:

// Pins muxing (from tool)
CLOCK_EnableClock(kCLOCK_PortA); /* Port A Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC); /* Port C Clock Gate Control: Clock enabled */

PORT_SetPinMux(PORTA, PIN16_IDX, kPORT_MuxAlt2);  /* PORTA16 (pin 46) is configured as SPI0_SOUT */
PORT_SetPinMux(PORTA, PIN17_IDX, kPORT_MuxAlt2);  /* PORTA17 (pin 47) is configured as SPI0_SIN */
PORT_SetPinMux(PORTC, PIN0_IDX, kPORT_MuxAlt2);    /* PORTC0 (pin 70) is configured as SPI0_PCS4 */
PORT_SetPinMux(PORTC, PIN5_IDX, kPORT_MuxAlt2);    /* PORTC5 (pin 77) is configured as SPI0_SCK */

#define WIFI_DSPI_MASTER_BASEADDR SPI0
#define WIFI_MASTER_CLK_SRC DSPI0_CLK_SRC
#define WIFI_MASTER_CLK_FREQ CLOCK_GetFreq(DSPI0_CLK_SRC)
#define WIFI_DSPI_MASTER_PCS_FOR_INIT kDSPI_MasterPcs0 // setting up the wrong one makes the thing work
#define WIFI_DSPI_MASTER_PCS_FOR_TRANSFER kDSPI_MasterPcs0 // same, if i set CS4 it will work inverted
#define WIFI_SPI_TRANSFER_BAUDRATE 500000U
extern dspi_transfer_t spi_WIFI_transfer;
extern dspi_master_config_t spi_WIFI_masterConfig;
extern dspi_master_ctar_config_t spi_WIFI_ctarConfig;

// CTAR config
spi_WIFI_ctarConfig.baudRate = WIFI_SPI_TRANSFER_BAUDRATE; // 500000
spi_WIFI_ctarConfig.bitsPerFrame = 8;
spi_WIFI_ctarConfig.cpol = kDSPI_ClockPolarityActiveHigh;
spi_WIFI_ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
spi_WIFI_ctarConfig.direction = kDSPI_MsbFirst;
spi_WIFI_ctarConfig.pcsToSckDelayInNanoSec = 1000000000U / WIFI_SPI_TRANSFER_BAUDRATE;
spi_WIFI_ctarConfig.lastSckToPcsDelayInNanoSec = 1000000000U / WIFI_SPI_TRANSFER_BAUDRATE;
spi_WIFI_ctarConfig.betweenTransferDelayInNanoSec = 1000000000U / WIFI_SPI_TRANSFER_BAUDRATE;

/*Driver configuration and init for SPI*/
spi_WIFI_masterConfig.whichCtar = kDSPI_Ctar0;
spi_WIFI_masterConfig.ctarConfig = spi_WIFI_ctarConfig;
spi_WIFI_masterConfig.whichPcs = WIFI_DSPI_MASTER_PCS_FOR_INIT;
spi_WIFI_masterConfig.enableContinuousSCK = false;
spi_WIFI_masterConfig.enableRxFifoOverWrite = true;
spi_WIFI_masterConfig.enableModifiedTimingFormat = false;
spi_WIFI_masterConfig.samplePoint = kDSPI_SckToSin0Clock;
spi_WIFI_masterConfig.pcsActiveHighOrLow = kDSPI_PcsActiveLow; // THIS IS NOT AFFECTING THE BEHAVIOR OF CS4 PIN!!
DSPI_MasterInit(WIFI_DSPI_MASTER_BASEADDR,&spi_WIFI_masterConfig, WIFI_MASTER_CLK_FREQ);

// comm test (works if I set PCS as PCS0 (unused one), so PCS4 will remain LOW)
spi_WIFI_transfer.txData = masterTxData;
spi_WIFI_transfer.rxData = masterRxData;
spi_WIFI_transfer.dataSize = 4;
spi_WIFI_transfer.configFlags = kDSPI_MasterCtar0 | WIFI_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;
DSPI_MasterTransferBlocking(WIFI_DSPI_MASTER_BASEADDR, &spi_WIFI_transfer);


 


Attached two screenshots of signal capturing with a logic analyzer.

 

I will really appreciate suggestions!

Thanks,
Riccardo

Outcomes