Sorry - in my haste I ended up only opening the last post.
I am using ALT 2 to set PTA11 to its SPI2_PCS0 functionality, same as that use in init_io in hal_spi.c in SPI demo. I had briefly, in error, tried to also add output code.
It does not matter if PCS0 is the traditional active low output when data is being transferred or high - just need it to actually change one way or the other before and after SPI transmission of a number of bytes.
My interpretation of the SPI_demo, is that it should be high when in the inactive state and low during the transmission. However as indicated it remains low and as far as I can see the signal, PTD11 should come out on B46 on the TWR-K60D100M - though I notice on the User Manual the SOUT an SIN pins appears to be crossed over.
Code being used:
static void init_io(void)
{
PORTD_PCR11 &= ~PORT_PCR_MUX_MASK; /* PTD11.*/
PORTD_PCR11 |= PORT_PCR_MUX(2); /* ALT2 for SPI2_PCS0, B46 on TWR bd.*/
PORTD_PCR12 &= ~PORT_PCR_MUX_MASK; /* PTD12 */
PORTD_PCR12 |= PORT_PCR_MUX(2); /* ALT2 for SPI2_CLK, B48 on TWR bd.*/
PORTD_PCR13 &= ~PORT_PCR_MUX_MASK; /* PTD13 */
PORTD_PCR13 |= PORT_PCR_MUX(2); /* ALT2 for SPI2_SOUT - Output, B45 on TWR bd */
PORTD_PCR14 &= ~PORT_PCR_MUX_MASK; /* PTD14 */
PORTD_PCR14 |= PORT_PCR_MUX(2); /* Alt2 for SPI2_SIN - Input, B44 on TWR bd.*/
}
/*The SPI demo has the following as separate procedures, the following just shows the raw code used for setting up the SPI port, but includes my comments on what I believe is happening.*/
SPI2_MCR |= SPI_MCR_MSTR_MASK; /* set bit 31 to '1' to select Master Mode. */
SPI2_MCR &= ~SPI_MCR_MDIS_MASK; /* enable the module clocks.*/
SPI2_MCR |= SPI_MCR_DIS_RXF_MASK | /* Rx FIFO is disabled.*/
SPI_MCR_DIS_TXF_MASK | /* Tx FIFO is disabled.*/
SPI_MCR_CLR_RXF_MASK | /* clear the Rx FIFO counter.*/
SPI_MCR_CLR_TXF_MASK; /* clear the Tx FIFO counter.*/
/* My interpretation is it is this line that determines whether PCS0 is high or low when inactive, with the SPI_demo setting the inactive state to high.*/
SPI2_MCR |= SPI_MCR_PCSIS(1<<0); /* bit 16, PCS0 = 1 - the inactive state of PCS0 is set high.*/
/* My interpretation is that this part of the code that is called when each byte is transmitted should change the state of the PCS0 output when 'end' is set when the last byte is being transmitted - whether is active low or high being determined by the MCR setting above. */
uint8 hal_spi_transfer_one_byte_SPI2(uint8 v, Bool end)
{
if(end)
SPI2_PUSHR = //SPI_PUSHR_CONT_MASK |
SPI_PUSHR_EOQ_MASK | /* Initially set all bits to '0' apart from bit 27 = '1' to indicate
last data in SPI queue.
bit 31 is set to '0' thus PCS signal will be negated after
completion of the transfer of the last byte.*/
SPI_PUSHR_PCS(1<<0) | /* bit 16 for PCS0.*/
(v); /* bit 15-0, add TxData.*/
else
SPI2_PUSHR = SPI_PUSHR_CONT_MASK | /* set all bits to '0' apart from bit 31 = '1' to keep the PCS
signal asserted between transfers.*/
SPI_PUSHR_PCS(1<<0) | /* bit 16 for PCS0 */
(v); /* bit 15-0, add TxData.*/
/* Wait for a byte to be sent and read in.*/
while((SPI2_SR & SPI_SR_TCF_MASK)==0) /* 1 when transfer complete.*/
;
SPI2_SR |= SPI_SR_TCF_MASK; /* clear the TCF flag */
return SPI2_POPR & 0xff;
}
Please advise if my interpretations are not correct and what to check next.
Thank you