View previous topic :: View next topic |
Author |
Message |
SBS
Joined: 15 Aug 2005 Posts: 18
|
Interrupt routine can't call function?? |
Posted: Thu Oct 27, 2005 8:50 pm |
|
|
I've got a timer setup to interrupt. Then on every third interrupt I want to call my read_adc() function. My code executes, but it doesn't ever appear to actually go into the read_adc() function. Nothing comes over RS232 from the read_adc() function. Also, it (MPLAB) won't let me put a breakpoint in the read_adc() function.
Why isn't the read_adc() function executing?
Code: |
#INT_TIMER2
void clock_isr()
{
if (count = 2){
printf(" read ADC ");
read_adc();
output_toggle(PIN_B2);
count = 0;
}
else
count ++;
}
void read_adc()
{
BYTE data1;
BYTE data2;
BYTE data3;
printf(" _ ");
spi_write(0x02); // Comm reg
spi_write(0x87); // ADCCON REG, Read Channel 1
spi_write(0x44); // Comm reg, Get ready to read
data1 = spi_read(0x00); // Read data 8-bits (data 0:7)
printf(" %X ", data1);
data2 = spi_read(0x00); // Read data 8-bits (data 8:15)
printf(" %X ", data2);
data3 = spi_read(0x00); // Read data 8-bits (data 16:23)
printf(" %X ", data3);
}
.
.
.
void main() {
enable_interrupts(INT_TIMER2);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
printf("Starting program... ");
// Cycle ADC ~RESET Pin
output_low(ADC_RESET);
delay_ms(100);
output_high(ADC_RESET);
// Setup SPI to ADC
setup_spi(SPI_MASTER | SPI_H_TO_L| SPI_CLK_DIV_64);
change_spi_mode(0);
setup_timer_2(T2_DIV_BY_16, 255, 16);
// Initialize ADC
init_adc();
while (TRUE){}
}
|
Thanks,
Sal |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 27, 2005 9:31 pm |
|
|
There are several criticisms that could be made, but at a minimum,
the lines shown in bold below should be corrected.
Quote: | #INT_TIMER2
void clock_isr()
{
if (count = 2){
printf(" read ADC ");
read_adc();
output_toggle(PIN_B2);
count = 0;
}
else
count ++;
} |
Hint: Look at a list of C operators.
Quote: |
void read_adc() {
BYTE data1;
BYTE data2;
BYTE data3; |
Hint: Look in the CCS manual at the list of functions. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Thu Oct 27, 2005 9:33 pm |
|
|
I don't know if this is the cause of your problem (it doesn't look like it), but the statement in your timer ISRis assignment, and it always returns true . Did you actually want ? |
|
|
SBS
Joined: 15 Aug 2005 Posts: 18
|
|
Posted: Thu Oct 27, 2005 9:39 pm |
|
|
Hi,
Thanks for the comments. I realized the count = 2 problem. It was a typo.
Ah... I guess I shouldn't name my functions the same as CCS functions, huh?
Thanks! |
|
|
|