CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Interrupt routine can't call function??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SBS



Joined: 15 Aug 2005
Posts: 18

View user's profile Send private message

Interrupt routine can't call function??
PostPosted: Thu Oct 27, 2005 8:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 27, 2005 9:31 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Thu Oct 27, 2005 9:33 pm     Reply with quote

I don't know if this is the cause of your problem (it doesn't look like it), but the statement in your timer ISR
Code:
count = 2
is assignment, and it always returns true . Did you actually want
Code:
count == 2
?
SBS



Joined: 15 Aug 2005
Posts: 18

View user's profile Send private message

PostPosted: Thu Oct 27, 2005 9:39 pm     Reply with quote

Hi,

Thanks for the comments. I realized the count = 2 problem. It was a typo. Smile

Ah... I guess I shouldn't name my functions the same as CCS functions, huh?

Thanks!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group