Hi Everybody,
I have DEMO9S12xDT512, I configure CAN0 and everything is OK
I took the same setting and try to configure CAN1 but its does not work.
CAN1 RX/Tx is in PM2/PM3 which can also be CAN0 or SPI.
I don't see in the datasheet if we should configure something to incidate that its CAN1 which should be used?
I saw
The CAN1 function (TXCAN1 and RXCAN1) takes precedence over the routed CAN0, the routed SPI0 and the
general purpose I/O function if the CAN1 module is enabled.
Can someone help me please?
Thank you in advance
My code:
My CAN1 Init Function:
void CAN1Init (void)
{
CAN1CTL0_SLPRQ = 1u; /* sleep mode*/
CAN1CTL0 = 0x01; /* Enter Initialization Mode */
while (! (CAN1CTL1 & 0x01)) {}; /* Wait for Initialization Mode
acknowledge (INITRQ bit = 1) */
CAN1CTL1 = 0x80u;
CAN1BTR0 = 0x9u; /* Prescaller = 10dec*/
CAN1BTR1 = 0x5Cu; // Tseg 1 = 13dec / Tseg2 = 6dec
/* Acceptance Filters */
CAN1IDAC = 0x00u;
/* Set four 16-bit Filters */
CAN1IDAR0 = ACC_CODE_ID100_HIGH; //|\ 16-bit Filter 0
CAN1IDMR0 = 0xFFu;//;MASK_CODE_ST_ID_HIGH; //| \__ Accepts Standard Data Frame Msg
CAN1IDAR1 = ACC_CODE_ID100_LOW; //| / with ID 0x100
CAN1IDMR1 = 0xFFu;//MASK_CODE_ST_ID_LOW; //|/
/* Acceptance Filters */
CAN1IDAC = 0x10; /* Set four 16-bit Filters */
CAN1IDAR2 = 0x00; //|\ 16-bit Filter 1
CAN1IDMR2 = 0xFFu;//MASK_CODE_ST_ID_HIGH; //| \__ Accepts Standard Data Frame Msg
CAN1IDAR3 = 0x00; //| / with ID 0x100
CAN1IDMR3 = 0xFFu;//MASK_CODE_ST_ID_LOW; //|/
CAN1IDAR4 = 0x00; //|\ 16-bit Filter 2
CAN1IDMR4 = 0xFFu;//MASK_CODE_ST_ID_HIGH; //| \__ Accepts Standard Data Frame Msg
CAN1IDAR5 = 0x00; //| / with ID 0x100
CAN1IDMR5 = 0xFFu;//MASK_CODE_ST_ID_LOW; //|/
CAN1IDAR6 = 0x00; //|\ 16-bit Filter 3
CAN1IDMR6 = 0xFFu;//MASK_CODE_ST_ID_HIGH; //| \__ Accepts Standard Data Frame Msg
CAN1IDAR7 = 0x00; //| / with ID 0x100
CAN1IDMR7 = 0xFFu;//MASK_CODE_ST_ID_LOW; //|/
CAN1CTL0 = 0x00; /* Exit Initialization Mode Request */
while ((CAN1CTL1&0x00) != 0) {;} /* Wait for Normal Mode */
CAN1RFLG = 0xC3u;
CAN1RIER = 0x01u;
}
My CAN1 SENT Function:
unsigned char CAN1SendFrame (unsigned char id,unsigned char priority, unsigned char length, unsigned char *txdata )
{
unsigned char txbuffer;
unsigned char index;
/*if (!CAN0TFLG) /* Is Transmit Buffer full?? */
/*return ERR_BUFFER_FULL;*/
CAN1TBSEL = CAN1TFLG; /* Select lowest empty buffer */
txbuffer = CAN1TBSEL; /*CAN0TBSEL; /* Backup selected buffer */
/* Load Id to IDR Register */
*((unsigned long *) ((unsigned long)(&CAN1TXIDR0))) = id;
for (index=0;index<length;index++)
{
/* Load data to Tx buffer * Data Segment Registers */
*(&CAN1TXDSR0 + index) = txdata[index];
}
CAN1TXDLR = length; /* Set Data Length Code */
CAN1TXTBPR = priority; /* Set Priority */
CAN1TFLG = txbuffer; /* Start transmission */
/* Wait for Transmission completion */
while ( (CAN1TFLG & txbuffer) != txbuffer);
}
FOR IT:
void CAN1_Receive_IT_Configuration_XGATE(void)
{
/* ALLOCATE EVENT TO XGATE */
/* Set interrupt control page to CAN1 Receive */
/* Send interrupt to XGate (priotiry level 1) */
/*CAN1 receive Vector Address 0xAA */
INT_CFADDR = 0xA0;
INT_CFDATA5 = 0x81;
}
In Xgate.cxgate
{CAN1RxXSR, (int)&MyData}, // Channel 55 - CAN1 receive
interrupt void CAN1RxXSR (MyDataType* __restrict pData)
{
unsigned char length1;
unsigned char index1;
unsigned char rxdata1[8];
pData->CAN1receive++;
length1 = (CAN1RXDLR & 0x0F);
for (index1=0; index1<length1; index1++)
rxdata1[index1] = *(&CAN1RXDSR0 + index1); /* Get received data */
CAN1RFLG = 0x01; /* Clear RXF */
}