Hi Petr,
Thx again for responding. I'm Still trying to figure out How to use the interrupt handler in order to transmit and receive data.
One way came in my mind is like:
uint16_t data[] = {0x0001, 0x0002, 0x0003};//Just a typical data
uint16_t recieve = 0;
int i =0;
void main(void)
{
PORT_init();//Init IER and some more stuff.
while(1)
{
if(i > sizeof(data) / sizeof(data[0]) - 1)//3 - 1 = 2
{
i = 0;
}
if(recieve == 0xAA)
{
//Do something
}
}
}
void LPSPI1_IRQHandler()
{
if(LPSPI1->SR & LPSPI_SR_RDF_MASK)//Data receive required
{
recieve= LPSPI1->RDR; /* Read received data */
LPSPI1->SR = LPSPI_SR_RDF_MASK; /* Clear RDF flag */
}
if(LPSPI1->SR & LPSPI_SR_TDF_MASK)//Data transmit required
{
LPSPI1->TDR = data[i++];/* Transmit data */
LPSPI1->SR = LPSPI_SR_TDF_MASK;/* Clear TDF flag */
}
}
1. Is there a more elegant way to receive or transmit data in interrupted mode ? like in polling(with void LPSPI1_transmit_16bits (uint8_t send) and uint8_t LPSPI1_receive_16bits)(void))
2. is that even a correct way to handle interrupts ? (In my example
Thx,
Dekel