Arlene Guest
|
CAN-not getting anything in RX buffers |
Posted: Wed Jul 27, 2005 11:35 am |
|
|
hi! I'm still having trouble with my PIC18F2480. I'm not getting anything in my RX buffers. Can someone please take a look at my functions. It would be really helpful. I've been using the can18xxx8.c and can18xxx8.h files. I'm also using MCP2551.
Thanks
Arlene
#fuses INTRC_IO, NOLVP, NOMCLR, BROWNOUT, BORV45, NOWDT,NOPBADEN,
PROTECT, CPB, WRTC, EBTRB, EBTR, CPD, IESO, WRTB, WRT//, WRTD
void can_setup()
{
struct rx_stat rxstat;
int data_in[8];
int32 rx_id;
int rx_len;
int data_out[8];
int32 tx_id=24;
int1 tx_ext=0;
int1 tx_rtr=0;
int tx_len=8;
int tx_pri=3;
int length;
for (i=0; i<8; i++)
{
data_out[i]=0;
data_in[i]=0;
}
can_initialize();
if (can_tbe())
{
tx_len=fgetc(streamB);
for (i= 0; i<tx_len; i++)
{
data_out[i]= fgetc(streamB);
}
i= can_putd(tx_id, data_out, tx_len, tx_pri, tx_ext, tx_rtr);
}
else
{
if(can_getd(rx_id, data_in, rx_len, rxstat))
{
for ( i=0; i<rxlen; i++)
{
putc(data_in[i], streamB);
}
}
}
}
void can_initialize(void)
{
can_set_mode(CAN_OP_CONFIG);
can_set_baud_rate(10400);
RXB0CON=0;
RXB0CON.rxm=CAN_RX_VALID;
RXB0CON.rxb0dben=CAN_USE_RX_DOUBLE_BUFFER;
RXB1CON=RXB0CON;
CIOCON.endrhi=CAN_ENABLE_DRIVE_HIGH;
CIOCON.cancap=CAN_ENABLE_CAN_CAPTURE;
can_set_id(RX0MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID);
can_set_id(RX0FILTER0, 0, CAN_USE_EXTENDED_ID);
can_set_id(RX0FILTER1, 0, CAN_USE_EXTENDED_ID);
can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL,
CAN_USE_EXTENDED_ID);
can_set_id(RX1FILTER2, 0, CAN_USE_EXTENDED_ID);
can_set_id(RX1FILTER3, 0, CAN_USE_EXTENDED_ID);
can_set_id(RX1FILTER4, 0, CAN_USE_EXTENDED_ID);
can_set_id(RX1FILTER5, 0, CAN_USE_EXTENDED_ID);
set_tris_b((*0xF93 & 0xFB ) | 0x08);
can_set_mode(CAN_OP_NORMAL);
} |
|