How to generate an interrupt when LPSPI sends a frame of data (CS is negative), and what flags can be used.
E.g:
LPSPI0->IER |= LPSPI_IER_TCIE(1);
LPSPI_Interupt_Enable(LPSPI0,LPSPI0_IRQn,0xC);
void LPSPI0_IRQHandler(void)
{
LPSPI0->SR |= LPSPI_SR_TCF_MASK;
}
This will always be interrupted, is this setting wrong?
You should rather use FCF flag
TCF is set whenever is transmit FIFO empty.
//init
LPSPI0->IER |= LPSPI_IER_FCIE(1);//LPSPI_IER_TCIE
LPSPI_Interupt_Enable(LPSPI0,LPSPI0_IRQn,0xC);
//read & write
uint8_t LPSPI_ReadWriteByte(LPSPI_Type *Instance,uint8_t byte)
{
uint8_t recieve = 0;
while((Instance->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);
/* Wait for Tx FIFO available */
Instance->TDR = byte; /* Transmit data */
Instance->SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */
// while((Instance->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
/* Wait at least one RxFIFO entry */
recieve= Instance->RDR; /* Read received data */
Instance->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
return recieve; /* Return received data */
}
void Spi_Transfer(LPSPI_Type *Instance,uint8_t *TxBuffer,uint8_t *RxBuffer,uint32_t length)
{
uint32_t i = 0;
Instance->TCR |= LPSPI_TCR_CONT(1)|LPSPI_TCR_CONTC(1);
for(i = 0;i<length;i++)
{
RxBuffer[i] = LPSPI_ReadWriteByte(Instance,TxBuffer[i]);
}
Instance->TCR &= ~LPSPI_TCR_CONTC_MASK;
Instance->SR |= LPSPI_SR_FCF_MASK;
}
//IRQ
void LPSPI0_IRQHandler(void)
{
LPSPI0->SR |= LPSPI_SR_FCF_MASK;
//LPSPI0->SR &= ~LPSPI_SR_FCF_MASK;
}
I can't transfer data according to the above settings, I don't know how to set it now.
I would use RDF and TDF flags, either for interrupt or polling methods.