I have a timer interrupt in which I set a flag.
Additionally in the isp I have an SSP1STAT call on Buffer Full.
The idea is that I am operating the SSP in Master Mode to read a 32 bit word using the 8 bit Serial Input Register. I am reading the SDI then or'ing it with a LONG variable. I then left shift the LONG to make room for the new SPI input.
Between Buffer Full interrupts I am returning to the program. So each pass is only once per buffer full.
- Code: Select all
char measure;
long measure1;
long instant_read;
void interrupt myIsr (void){
// test for timer timeout (250 usec on a 4 MHz external clock)
if (TMR3IF) { // If timer int. kick counter
if (timer3_int)
timer3_int--; // decriment counter
TMR3H = 0xFF;
TMR3L = 0x41;
TMR3IF = FALSE; // clear for next timer int
TMR3IE = TRUE; // Reenable interrupt
}
// Test for ADC data ready
if ((SSP1STAT & 0x01)) { // Buffer full
measure = SSP1BUF; // Also clears BF bit
adc_byte_flag = 1;
if (byte_count++ <= 3) { // if not full 32 bits
measure1 |= measure;
measure1 = measure1 << 8; // xfer to avg_read pile
SSP1BUF = LOW; // Start download again?
}
else {
new_reading_flag = TRUE; // Flag new reading to be read before next conversion end
byte_count = 0; // Init count
instant_read = measure1;
measure1 = 0UL; // Set to zero
adc_byte_flag = 0;
SSP1IF = FALSE; // Clear flag
SSP1IE = TRUE; // Reenable interrupt
(Start a new ADC conversion via a port bit)
}
}
}
in the program the adc_byte_flag is used in program to start the SPI master operation via:
- Code: Select all
if (test_busy() == NO && adc_byte_flag == 0) // wait next ADC conversion completed and not in the process of reading it already
SSP1BUF = LOW; // Starts read if conversion complete
The timer interrupt operates fine. The SSP1STAT answers the interrupt but SCLK continues to pour out of the SCLK (in 8 bit groups) as if the SDO were being written to in a continuous fashion or as if the SSP1STAT.BF were not being cleared when the SSPBUF was read. Since the BF is a read-only it cannot be manually cleared.
Has anyone had any experience that might help me?
Side Note: the forum removes the spaces making the program easier to read.