seidleroni
Joined: 08 Sep 2008 Posts: 21
|
CAN RX isn't working...short code example posted |
Posted: Fri Nov 21, 2008 1:50 pm |
|
|
I am using the short code below, but the CAN receive interrupts aren't getting triggered (and neither is the can_kbhit). The printf's don't output anything, and the LED on PIN_A4 isn't toggling when I send the PIC a CAN message (although it does toggle every second according to the code). I know that CAN is working because I'm receiving CAN messages FROM the PIC, AND I know that my messages going TO the PIC are getting acknowledged because my PC program doesn't show any errors when I send the PIC the command. Any questions why I'm getting no "action" when the PIC is receiving a CAN packet?
Here's the code... (I'm using compiler version 4.081)
Code: | #include <18F4685.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <can-18xxx8.c>
#FUSES H4
#use delay (clock=40M, oscillator=10M)
#USE RS232(Baud=19200, XMIT=PIN_B6, RCV=PIN_B7, BITS=8, PARITY=N, ERRORS)
#int_CANRX1
CANRX1_isr()
{
output_bit(PIN_A4, !input(PIN_A4));
printf("1");
}
#int_CANRX0
CANRX0_isr()
{
output_bit(PIN_A4, !input(PIN_A4));
printf("0");
}
void canSetBaud(void)
{
can_set_mode(CAN_OP_CONFIG);
BRGCON1.brp = 7;
BRGCON1.sjw = 0;
BRGCON2.prseg = 2;
BRGCON2.seg1ph = 7;
BRGCON2.sam = 0;
BRGCON2.seg2phts = TRUE;
BRGCON3.seg2ph = 7;
BRGCON3.wakfil = FALSE;
RXB0CON.rxb0dben=FALSE;
can_set_mode(CAN_OP_NORMAL);
}
void main()
{
int buffer[8], rx_len;
int32 id = 0xAFAFAFAF;
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_CANRX1);
enable_interrupts(INT_CANRX0);
enable_interrupts(GLOBAL);
buffer[0] = 0x00;
buffer[1] = 0x11;
buffer[2] = 0x22;
buffer[3] = 0x33;
buffer[4] = 0x44;
buffer[5] = 0x55;
buffer[6] = 0x66;
buffer[7] = 0x77;
can_init();
canSetBaud();
//set_adc_channel(0);
while (TRUE)
{
delay_ms(1000);
output_bit(PIN_A4, !input(PIN_A4));
if (can_kbhit())
{
output_bit(PIN_A4, !input(PIN_A4));
}
can_putd(id,buffer,8,3,TRUE,FALSE);
}
} |
|
|