!
Hi,
My canbus module send data fine but does not accept the incomming messages and im out of ideas. A push in the right direction will be greatly appreciated.
1.
CAN0IDAC_IDAM = 0x00U; /* Set the acceptance mode 2x32bit */
CAN0IDAR0 = 0x00U;
CAN0IDAR1 = 0x00U;
CAN0IDAR2 = 0x00U;
CAN0IDAR3 = 0x80U;
with mask0-3 0x00 im sending my messages to 0x80.
2. same id with mask0-2 0xFF and mask3 0x00. im sending my messages to 0x80.
3. same id with mask0-3 0xFF. in theory it should accept everything at this point. im sending my messages to 0x80.
4.im setting the SRR and IDE bits in to the id
CAN0IDAR0 = 0x00U;
CAN0IDAR1 = 0x18U;
CAN0IDAR2 = 0x00U;
CAN0IDAR3 = 0x10U;
mask0-3= 0x0
now im sending to the ids;
- 0x10
-0x8
-0x180010
well im just trying random stuff now. i managed to get some data with
ID0-3= 0x0
mask0-2= 0x0 and mask3=0xFF but it worked only for a couple of days and it is not acceptable for the actual project.
So im in need of help. What im i doing wrong?
Thanks.
Yuce
void CAN1_Init(void)
{
/* CAN0CTL1: CANE=1,CLKSRC=0,LOOPB=0,LISTEN=0,BORM=0,WUPM=0,SLPAK=0,INITAK=0 */
CAN0CTL1 = 0x80U; /* Set the control register */
/* CAN0CTL0: RXFRM=0,RXACT=0,CSWAI=0,SYNCH=0,TIME=0,WUPE=0,SLPRQ=0,INITRQ=1 */
CAN0CTL0 = 0x01U; /* Set the control register */
CAN0IDAC_IDAM = 0x00U; /* Set the acceptance mode */
CAN0IDAR0 = 0x00U; /* Set the acceptance code, register CAN0IDAR0 */
CAN0IDAR1 = 0x18U; /* Set the acceptance code, register CAN0IDAR1 */
CAN0IDAR2 = 0x00U; /* Set the acceptance code, register CAN0IDAR2 */
CAN0IDAR3 = 0x10U; /* Set the acceptance code, register CAN0IDAR3 */
CAN0IDAR4 = 0x00U; /* Set the acceptance code, register CAN0IDAR4 */
CAN0IDAR5 = 0x00U; /* Set the acceptance code, register CAN0IDAR5 */
CAN0IDAR6 = 0x00U; /* Set the acceptance code, register CAN0IDAR6 */
CAN0IDAR7 = 0x00U; /* Set the acceptance code, register CAN0IDAR7 */
CAN0IDMR0 = 0x00U; /* Set the acceptance mask, register CAN0IDMR0 */
CAN0IDMR1 = 0x00U; /* Set the acceptance mask, register CAN0IDMR1 */
CAN0IDMR2 = 0x00U; /* Set the acceptance mask, register CAN0IDMR2 */
CAN0IDMR3 = 0x00U; /* Set the acceptance mask, register CAN0IDMR3 */
CAN0IDMR4 = 0x00U; /* Set the acceptance mask, register CAN0IDMR4 */
CAN0IDMR5 = 0x00U; /* Set the acceptance mask, register CAN0IDMR5 */
CAN0IDMR6 = 0x00U; /* Set the acceptance mask, register CAN0IDMR6 */
CAN0IDMR7 = 0x00U; /* Set the acceptance mask, register CAN0IDMR7 */
/* CAN0BTR0: SJW1=0,SJW0=1,BRP5=0,BRP4=0,BRP3=0,BRP2=0,BRP1=0,BRP0=1 */
CAN0BTR0 = 0x41U; /* Set the device timing register */
/* CAN0BTR1: SAMP=0,TSEG22=1,TSEG21=1,TSEG20=1,TSEG13=0,TSEG12=1,TSEG11=1,TSEG10=0 */
CAN0BTR1 = 0x76U; /* Set the device timing register */
CAN0CTL1_CLKSRC = 0x00U; /* Select the clock source from crystal */
CAN0CTL0_INITRQ = 0x00U; /* Start device */
while(CAN0CTL1_INITAK) {} /* Wait for enable */
/* CAN0RFLG: WUPIF=1,CSCIF=1,RSTAT1=1,RSTAT0=1,TSTAT1=1,TSTAT0=1,OVRIF=1 */
CAN0RFLG |= 0xFEU; /* Reset error flags */
/* CAN0RIER: WUPIE=0,CSCIE=1,RSTATE1=1,RSTATE0=1,TSTATE1=1,TSTATE0=1,OVRIE=0,RXFIE=1 */
CAN0RIER = 0x7DU; /* Enable interrupts */
}
Solved! Go to Solution.
Hi,
I will share my answer I sent to you via support system also here.
Best regards,
Ladislav
It always helps reading documentation.
You say you send to 0x80, then "the same id in mask", etc. Looks like you don't understand what CAN message Id you are sending to. CAN message Id doesn't appear in its native form in any of MSCAN regsiters. Instead CAN Rx buffer Identifier registers, CAN Tx buffer identifier registers and CAN mask and filter registers follow the same identifier mapping. You need to find in your S12XHY datasheet two figures, one is called Receive/Transmit Message Buffer — Extended Identifier Mapping
, and another one for Standard Identifier Mapping.
Regarding filters. '1' in IDAM reg makes corresponging receive buffer IDx, SRR, IDE or RTR bit don't care. '0' bit in IDAMx makes the same bit in receive buffer compared to value in corresponging IDAR regs of all enabled filters. Message is accepted when all identifie bits in receive buffer have corresponding '1' in IDAMx or match values programmed in IDAR.
Hi Edward,
Thanks for the fast response. In the datasheet under 11.4.3 Identifier Acceptance Filter on page 380 it says
"A filter hit is indicated to the application software by a set receive buffer full flag (RXF = 1) and three bits
in the CANIDAC register (see Section 11.3.2.12, “MSCAN Identifier Acceptance Control Register
(CANIDAC)”). These identifier hit flags (IDHIT[2:0]) clearly identify the filter section that caused the
acceptance."
datasheet
http://cache.freescale.com/files/microcontrollers/doc/ref_manual/MC9S12XHY256RMV1.pdf
So i thought canbus module would only send an interrupt if there is correct compare between acceptance filter and receive message buffer.
To clarify 4. point
4.im setting the SRR and IDE bits in to the id
IDAR0 = 0x00U;
IDAR1 = 0x18U; //IDE=1 SRR=1
IDAR2 = 0x00U;
IDAR3 = 0x10U; //ID6,5,4=0 ID3=1 ID2,1,0=0 RTR=0
IDMR0 = 0x00U;
IDMR1 = 0x00U;
IDMR2 = 0x00U;
IDMR3 = 0x00U;
now im sending from my usb-can to the ids;
-0x8 //this id consist of ID bits so ID3=1
-0x180010 //this id structured like the acceptance registers IDE=1 SRR=1 ID3=1
- 0x10 // this msg just in case
i dont get a single hit
Im sorry but can you give me an example on how to set the register to accept the id 0x80 for example.
Thanks for you patience.
Yuce
I know nothing about your usb-can device. Your IDAR/IDMR setting seem conforming to Extended identifier = 8. But it is not clear what identifier does your usb-can send, standard or extended. If there's no command line switch for ext/std, then perhaps it is sending standard id messages when Id<=2047 and extended id messagees when Id>=2048. And standard Id's need different IDAM/IDAR setup.
You mey set all IDMR to all 0xFF to receive all CAN messages. See what your usb-can really sends
Well there is a check-box for extended id and another usb can device shows the id type correctly.
CAN0IDAR0 = 0x00U; /* Set the acceptance code, register CAN0IDAR0 */
CAN0IDAR1 = 0x18U; /* Set the acceptance code, register CAN0IDAR1 */
CAN0IDAR2 = 0x00U; /* Set the acceptance code, register CAN0IDAR2 */
CAN0IDAR3 = 0x10U; /* Set the acceptance code, register CAN0IDAR3 */
CAN0IDMR0 = 0xFFU; /* Set the acceptance mask, register CAN0IDMR0 */
CAN0IDMR1 = 0xFFU; /* Set the acceptance mask, register CAN0IDMR1 */
CAN0IDMR2 = 0xFFU; /* Set the acceptance mask, register CAN0IDMR2 */
CAN0IDMR3 = 0xFFU; /* Set the acceptance mask, register CAN0IDMR3 */
messages to
-0x8 //this id consist of ID bits so ID3=1
-0x180010 //this id structured like the acceptance registers IDE=1 SRR=1 ID3=1
- 0x10 // this msg just in case
Still no hit.
here is my can1.c
0xFF's in IDMR make filter opened, you should receive everything. Are you sure message from usb-can is sent properly, no bus errors? Is there right burst of pulses and not non-stop sequence of pulses? Are you sure you have no wiring or soldering error?
I have no time to study your code, but it is full or flag clear bugs. You can't use bitwise-OR operation with flags registers.
CANRFLG |= 1; //is wrong, clears all CANRFLG flags
CANRFLG &= ~1; // is wrong, clears bit7..bit1 flags, leaves bit0 flag untouched.
CANRFLG = 1; // is correct, clears bit0 flag
CANRFLG &= 1; // is correct, clears bit0 flag, bit7..bit1 are left untouched.
The same ^^ applies to CANTX flags, timer flags and all other S12 flags registers, which include more than one flag bits, which are clearable writing '1' to flag.
im reading messages fine on a mc9s12p128.
CAN0RFLG |= 0xFEU; /* Reset error flags */
this is a correct code, it should clear all. there are no flag clear bugs i can see.
i can receive messages from the device just fine. it just doesnt accept.
CAN0RFLG |= 0xFEU; | /* Reset error flags */ |
No, it is wrong. Try executing this when RXF flag is set. RXF (bit0) will be cleared too.