RichardH
Newbie level 5
Hi
I am trying to clock a continuous data stream out using the SPI port (I never read anything back), ideally, I would like a 16 bit word with an interrupt to reload the SPI1BUF every time it is empty.
I set up the SPI
TRISF = 0x0140;
CLKDIV = 0x0040;
SPI1CON1 = 0x013B;
SPI1CON2 = 0x0000;
SPI1STATbits.SISEL0 = 1; // set SISEL to 101 to enable interrupt driven output
SPI1STATbits.SISEL1 = 0;
SPI1STATbits.SISEL2 = 1;
SPI1CON1bits.MODE16 = 1; // put into 16 bit mode
SPI1STATbits.SPIEN = 1; // Enable the SPI
IFS0bits.SPI1IF = 1; // clear interrupt flag
IEC0bits.SPI1IE = 1; // enable interrupt
my interrupt routine
void __attribute__((__interrupt__, no_auto_psv)) _SPI1Interrupt(void)
{
SPI1BUF = data[count++];
IFS0bits.SPI1IF = 0;
}
the interrupt gets called 2 or 3 times, then never again..........but I am clearing the flag, so I am not sure why it stops.
I tried adding
IFS0bits.SPF1IF = 0;
to the interrupt service routine, just in case I was getting an error (as I am not receiving anything), but this doesn't help.
Any ideas what I have missed?
Thanks
Richard
Added after 5 hours 36 minutes:
Having been trying different things, I have found that If I set
SPI1STATbits.SPIROV =0;
in the interrupt, then it seems to continue onwards with the interrupt, however, I am not sure this is correct as I dont seem to see any clock and data pulses coming out.
Any ideas?
I am trying to clock a continuous data stream out using the SPI port (I never read anything back), ideally, I would like a 16 bit word with an interrupt to reload the SPI1BUF every time it is empty.
I set up the SPI
TRISF = 0x0140;
CLKDIV = 0x0040;
SPI1CON1 = 0x013B;
SPI1CON2 = 0x0000;
SPI1STATbits.SISEL0 = 1; // set SISEL to 101 to enable interrupt driven output
SPI1STATbits.SISEL1 = 0;
SPI1STATbits.SISEL2 = 1;
SPI1CON1bits.MODE16 = 1; // put into 16 bit mode
SPI1STATbits.SPIEN = 1; // Enable the SPI
IFS0bits.SPI1IF = 1; // clear interrupt flag
IEC0bits.SPI1IE = 1; // enable interrupt
my interrupt routine
void __attribute__((__interrupt__, no_auto_psv)) _SPI1Interrupt(void)
{
SPI1BUF = data[count++];
IFS0bits.SPI1IF = 0;
}
the interrupt gets called 2 or 3 times, then never again..........but I am clearing the flag, so I am not sure why it stops.
I tried adding
IFS0bits.SPF1IF = 0;
to the interrupt service routine, just in case I was getting an error (as I am not receiving anything), but this doesn't help.
Any ideas what I have missed?
Thanks
Richard
Added after 5 hours 36 minutes:
Having been trying different things, I have found that If I set
SPI1STATbits.SPIROV =0;
in the interrupt, then it seems to continue onwards with the interrupt, however, I am not sure this is correct as I dont seem to see any clock and data pulses coming out.
Any ideas?