Hola, les dejo el archivo can-18F4580.c sacando algunas funciones que calculo que no interesaban para el análisis.
Yo estoy usando un 18F4585, esto conlleva alguna modificación?.
Muchas gracias por la paciencia y predisposición.
Saludos cordiales,
Ariel.
/////////////////////////////////////////////////////////////////////////
//// can-18F4580.c ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// Version History ////
//// ////
//// Jul 27 04 - can_init() uses CAN_USE_EXTENDED_ID instead of ////
//// setting all RX filters to extended. ////
//// ////
//// Feb 24 04 - can_get_id() fixed for EID<18:20>. ////
//// ////
/////////////////////////////////////////////////////////////////////////
#include <can-18F4580.h>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#if CAN_DO_DEBUG
#define can_debug printf
#else
#define can_debug
#endif
//macros
#define can_kbhit() (RXB0CON.rxful || RXB1CON.rxful || B0CONR.rxful || B1CONR.rxful || B2CONR.rxful || B3CONR.rxful || B4CONR.rxful || B5CONR.rxful)
#define can_tbe() (!TXB0CON.txreq || !TXB1CON.txreq || !TXB2CON.txreq || !B0CONT.txreq || !B1CONT.txreq || !B2CONT.txreq || !B3CONT.txreq || !B4CONT.txreq || !B5CONT.txreq)
#define can_abort() (CANCON.abat=1)
// current mode variable
// used by many of the device drivers to prevent damage from the mode
//
int curmode;
int curfunmode;
////////////////////////////////////////////////////////////////////////
//
// can_init()
//
//////////////////////////////////////////////////////////////////////////////
void can_init(void) {
can_set_mode(CAN_OP_CONFIG); //must be in config mode before params can be set
can_set_baud();
curfunmode=0;
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); //set mask 0
can_set_id(RXFILTER0, 0, CAN_USE_EXTENDED_ID); //set filter 0 of mask 0
can_set_id(RXFILTER1, 0, CAN_USE_EXTENDED_ID); //set filter 1 of mask 0
can_set_id(RX1MASK, CAN_MASK_ACCEPT_ALL, CAN_USE_EXTENDED_ID); //set mask 1
can_set_id(RXFILTER2, 0, CAN_USE_EXTENDED_ID); //set filter 0 of mask 1
can_set_id(RXFILTER3, 0, CAN_USE_EXTENDED_ID); //set filter 1 of mask 1
can_set_id(RXFILTER4, 0, CAN_USE_EXTENDED_ID); //set filter 2 of mask 1
can_set_id(RXFILTER5, 0, CAN_USE_EXTENDED_ID); //set filter 3 of mask 1
// set dynamic filters
can_set_id(RXFILTER6, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER7, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER8, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER9, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER10, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER11, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER12, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER13, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER14, 0, CAN_USE_EXTENDED_ID);
can_set_id(RXFILTER15, 0, CAN_USE_EXTENDED_ID);
set_tris_b((*0xF93 & 0xFB ) | 0x08); //b3 is out, b2 is in
can_set_mode(CAN_OP_NORMAL);
}
////////////////////////////////////////////////////////////////////////
//
// can_set_baud()
////////////////////////////////////////////////////////////////////////
void can_set_baud(void) {
# ifdef Set_125K_Baud {
BRGCON1 = 0x01;
BRGCON2 = 0xBA; //modificado 5/11/07 para usar CAN a 125 KBps
BRGCON3 = 0x07; //con reloj a 10 MHz
}
#endif
#ifdef Set_250K_Baud {
BRGCON1 = 0x00;
BRGCON2 = 0xBA; //modificado 5/11/07 para usar CAN a 250 KBps
BRGCON3 = 0x07; //con reloj a 10 MHz
}
#endif
#ifdef Set_500K_Baud {
BRGCON1 = 0x00;
BRGCON2 = 0x92; //modificado 5/11/07 para usar CAN a 500 KBps
BRGCON3 = 0x02; //con reloj a 10 MHz
}
#endif
}
////////////////////////////////////////////////////////////////////////
//
// can_set_mode
////////////////////////////////////////////////////////////////////////
void can_set_mode(CAN_OP_MODE mode) {
CANCON.reqop=mode;
while( (CANSTAT.opmode) != mode );
}
////////////////////////////////////////////////////////////////////////
//
// can_set_functional_mode
////////////////////////////////////////////////////////////////////////////////
void can_set_functional_mode(CAN_FUN_OP_MODE mode)
{
can_set_mode(CAN_OP_CONFIG); //must be in config mode before params can be set
ECANCON.mdsel=mode;
curfunmode=mode;
can_set_mode(CAN_OP_NORMAL);
}
////////////////////////////////////////////////////////////////////////
//
// can_set_id()
////////////////////////////////////////////////////////////////////////
void can_set_id(int* addr, int32 id, int1 ext) {
//int *ptr;
//ptr=addr;
if (ext) { //extended
//eidl
*addr=make8(id,0); //0:7
//eidh
addr--;
*addr=make8(id,1); //8:15
//sidl
addr--;
*addr=make8(id,2) & 0x03; //16:17
*addr|=(make8(id,2) << 3) & 0xE0; //18:20
*addr|=0x08;
//sidh
addr--;
*addr=((make8(id,2) >> 5) & 0x07 ); //21:23
*addr|=((make8(id,3) << 3) & 0xF8);//24:28
}
else { //standard
//eidl
*addr=0;
//eidh
addr--;
*addr=0;
//sidl
addr--;
*addr=(make8(id,0) << 5) & 0xE0;
//sidh
addr--;
*addr=(make8(id,0) >> 3) & 0x1F;
*addr|=(make8(id,1) << 5) & 0xE0;
}
}
////////////////////////////////////////////////////////////////////////////////
//
// can_set_standard_id
////////////////////////////////////////////////////////////////////////////////
void can_set_standard_id(int * addr, int32 id)
{
//eidl
*addr=0;
//eidh
addr--;
*addr=0;
//sidl
addr--;
*addr=(make8(id,0) << 5) & 0xE0;
//sidh
addr--;
*addr=(make8(id,0) >> 3) & 0x1F;
*addr|=(make8(id,1) << 5) & 0xE0;
}
////////////////////////////////////////////////////////////////////////////////
//
// can_set_extended_id
////////////////////////////////////////////////////////////////////////////////
void can_set_extended_id(int * addr, int32 id)
{
//eidl
*addr=make8(id,0); //0:7
//eidh
addr--;
*addr=make8(id,1); //8:15
//sidl
addr--;
*addr=make8(id,2) & 0x03; //16:17
*addr|=(make8(id,2) << 3) & 0xE0; //18:20
*addr|=0x08;
//sidh
addr--;
*addr=((make8(id,2) >> 5) & 0x07 ); //21:23
*addr|=((make8(id,3) << 3) & 0xF8);//24:28
}