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.
SIM_MemMapPtr sim = SIM_BASE_PTR;
//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 = PORT_PCR_MUX(2); /* DSPI0.PCS0 */
pctl->PCR = PORT_PCR_MUX(2); /* DSPI0.PCS1 */
pctl->PCR = PORT_PCR_MUX(2); /* DSPI0.PCS2 */
pctl->PCR = PORT_PCR_MUX(2); /* DSPI0.SCK */
pctl->PCR = PORT_PCR_MUX(2); /* DSPI0.SOUT */
pctl->PCR = 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:
ezp_spi_handle = fopen("spi0:1", NULL);
ezp_spi_handle = fopen("spi0:2", NULL);
ezp_spi_handle = fopen("spi0:3", NULL);
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.