AnsweredAssumed Answered

MQX SPI chip select problem

Question asked by pk2 on Sep 2, 2014
Latest reply on Sep 18, 2014 by pk2

I am having a problem using the SPI CS signals in my K60 application.  My application uses SPI0 and addresses three devices using 3 CS signals (CS0, CS1, and CS2).  I read some other posts here and thought I had things working for CS0 and CS1.  However CS2 does not toggle when it should.   I am using MQX4.1 and CW 10.4. 


In my bsp I changed init_gpio.c by modifying case 0 in the _bsp_dspi_io_init function as shown below.


_mqx_int _bsp_dspi_io_init


    uint32_t dev_num



    SIM_MemMapPtr   sim = SIM_BASE_PTR;

    PORT_MemMapPtr  pctl;


    switch (dev_num)


        case 0:


//Modified Code for 3 chip select SPI0 which is on PORTC of the K60.



            /* Configure GPIOC for DSPI0 peripheral function */


            pctl = (PORT_MemMapPtr)PORTC_BASE_PTR;


            pctl->PCR[4] = PORT_PCR_MUX(2);     /* DSPI0.PCS0   */

            pctl->PCR[3] = PORT_PCR_MUX(2);     /* DSPI0.PCS1   */

            pctl->PCR[2] = PORT_PCR_MUX(2);     /* DSPI0.PCS2   */

            pctl->PCR[5] = PORT_PCR_MUX(2);     /* DSPI0.SCK    */

            pctl->PCR[6] = PORT_PCR_MUX(2);     /* DSPI0.SOUT   */

            pctl->PCR[7] = PORT_PCR_MUX(2);     /* DSPI0.SIN    */


            /* Enable clock gate to DSPI0 module */

            sim->SCGC6 |= SIM_SCGC6_DSPI0_MASK;



In my application I open/close the SPI0 port depending upon which of the 3 devices I need to address. Using the below code:


  switch (chip_sel)


case (0):

          ezp_spi_handle = fopen("spi0:1", NULL);


  case (1):

            ezp_spi_handle = fopen("spi0:2", NULL);


  case (2):

            ezp_spi_handle = fopen("spi0:3", NULL);



            break;                //




  When the application runs, I get a valid file handle for all 3 cases.  When "spi0:3" is used, I am expecting CS2 to toggle but CS 1 toggles!!


  Are there any examples of how to properly configure a BSP to use more than 2 chip SPI select signals with MQX.