I am using SPI0 on a MK20DN512VLK10 with MQX 4.0 and having trouble getting anything out of PC0.
_bsp_dspi_io_init has been modified for the pins on PORTA…
case 0:
/* Configure GPIOD for SPI0 peripheral function */
pctl = (PORT_MemMapPtr)PORTA_BASE_PTR;
pctl->PCR[14] = PORT_PCR_MUX(2); /* DSPI0.PCS0 */
pctl->PCR[15] = PORT_PCR_MUX(2); /* DSPI0.SCK */
pctl->PCR[16] = PORT_PCR_MUX(2); /* DSPI0.SOUT */
pctl->PCR[17] = PORT_PCR_MUX(2); /* DSPI0.SIN */
/* Enable clock gate to SPI0 module */
sim->SCGC6 |= SIM_SCGC6_SPI0_MASK;
break;
The io channel is initialized and accessed with…
adc_spi = fopen (ADC_CHANNEL, NULL);
if (NULL == adc_spi)
error = TRUE;
param = 500000; // set baud rate
if (SPI_OK != ioctl (adc_spi, IO_IOCTL_SPI_SET_BAUD, ¶m))
error = TRUE;
param = SPI_CLK_POL_PHA_MODE0; // set clock mode
if (SPI_OK != ioctl (adc_spi, IO_IOCTL_SPI_SET_MODE, ¶m))
error = TRUE;
param = SPI_DEVICE_BIG_ENDIAN; // set endianess
if (SPI_OK != ioctl (adc_spi, IO_IOCTL_SPI_SET_ENDIAN, ¶m))
error = TRUE;
param = SPI_DEVICE_MASTER_MODE; // set transfer mode
if (SPI_OK != ioctl (adc_spi, IO_IOCTL_SPI_SET_TRANSFER_MODE, ¶m))
error = TRUE;
param = 1; // set CS0
if (SPI_OK != ioctl(adc_spi, IO_IOCTL_SPI_SET_CS, ¶m))
error = TRUE;
if (SPI_OK != ioctl (adc_spi, IO_IOCTL_SPI_READ_WRITE, &adc_rw))
error = TRUE;
I used the IAR debugger to examine the registers and verified that the PortA PCR[14] through PCR[17] are set correctly with avalue of 0x200. I also verified that the SPI0 PUSHR has both CONT=1 and PCS=0x01. The SPI data lines and clock are all working but PORTA[14] just sits there in a high impedance state. Am I missing a step to enable PCS0 as an output?