View previous topic :: View next topic |
Author |
Message |
mrad13
Joined: 28 Apr 2013 Posts: 3
|
trouble with the #INT_RB interruption and SPI interface |
Posted: Sun Apr 28, 2013 4:52 pm |
|
|
hi all i have trouble with the #INT_RB interruption. I use PIC18F4550. I sent data from PIC to ADS1299 over the SPI interface but the INT_RB interruption is only executed at the last of program, not when B4 change level. If any one can explain me what to do??
thnx |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Apr 28, 2013 5:15 pm |
|
|
The folks here are not mind readers.
You have to provide a short program that demonstrates the problem.
Be sure to include all the setup and processor definition lines. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
mrad13
Joined: 28 Apr 2013 Posts: 3
|
|
Posted: Sun Apr 28, 2013 5:53 pm |
|
|
Code: | #int_RB
void RB_isr(void)
{
disable_interrupts(INT_RB);
output_low(CS);
SPI_WRITE(0xFF);
Delay_ms(20);
// val=SPI_READ(0);
output_high(CS);
//printf("%s",val);
}
void main()
{
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
while(true)
{
output_low(CS);
SPI_WRITE(0x01);
output_high(CS);
output_low(CS);
SPI_WRITE(0x02);
output_high(CS);
output_low(CS);
SPI_WRITE(0x03);
output_high(CS);
output_low(CS);
SPI_WRITE(0x04);
output_high(CS);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
}
}
|
Ok this is my code it supposed to send the values 0x01 0x02 0x03 0x04 over the SPI interface and if there is an interruption on B4 the value 0xFF is sent on SPI. But when i simulate it with ISIS Proteus and when i provoke an interruption thanks to a button relied to B4 he continue sending all the values then he send the value 0XFF. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Apr 28, 2013 8:18 pm |
|
|
rule #1) please read sticky PIC101
..contains important information
rule #2) Proteus aka ISIS is BUSTED.
..no one here wants to waste their time recoding busted code
rule #3) you do not need to disable interrupts within it's own ISR
..the CCS C compiler does this for you !
rule #4) never put delays within any ISR
..ISRs are supposed to be fast, no thumb twiddling allowed
rule #5) you _must_ read portB to clear the interrupt status
..explained in the datasheet of the PIC(all are the same,in this aspect.
rule#6) you shouldn't use printf within the ISR
..again, ISRs are supposed to be fast,printf take 'forever'.
rule #7) ISRs _must_ be short and fast!
..get in,set a flag or two,update a variable, then get out, FAST
hth
jay |
|
|
|