Hi all,
First time using MSCAN, and as it was to be expected I have some problems.
Trying to get a 50Kbps rate (low enough for now to not worry much about possible clock accuracy issues), using the following parameters:
CAN Driver: MCZ33902 (has a 40Kbps minimum rate)
DZ32 MCU bus clock: 16MHz
CAN prescaler: 32 (gives CAN clock 500KHz)
Prop Seg: 3 time quanta
Seg1: 3 time quanta
Seg2: 3 time quanta
Total bit time quanta: 10
RJW: 3
CANBTR0_VALUE: 158 [$009E]
CANBTR1_VALUE: 37 [$0025]
On the other end I have a CAN232 (www.can232.com) dongle set at 50Kbps, used to send a packet and try to see it being received on the MCU side, but no luck.
I may have some serious misconceptions about how the bit time quanta are supposed to be divided. For example, it may be possible to get the same CAN bps rate (say 50Kbps) using various bit quanta with different clocks. Will a 50Kbps rate work between two systems if one of them uses 10 time quanta per bit and the other achieves the same bps rate using, say, 20 time quanta?
I've read the relevant parts of AN1798, bosch_cia99-can-bit-timing.pdf, and the official Bosch specification, but still can't be sure if I have it correctly.
Also, I read in some application note that one should not use the internal oscillator FLL/PLL for CAN clock, but since it was too vague, I believe this is related to speeds higher than 125Kbps. I'm way lower than that, so I hope this would not be a problem, as the clock tolerance is way below 1.58% seen in some of these references. If my settings seem correct to you, then the last thing to try is to use an external clock.
TIA
Calculations look ok. But I would verify using oscilloscope if you have right timing. Disconnect PC end from CAN bus and try to send some message from MCU. Shortest pulse you see on the bus should be close enough to 1/50kHz=20us. Now disconnect MCU and try to send from PC. You should see the same shortest pulse width, else nodes won't communicate properly.
Didn't you forget to set CANCRL1.CLKSRC bit for bus clock source?
Number of time quanta can be different on different nodes, but bit time should be the same.
For CanOpen applicaion, 16MHz clock and 50bps I used 1/20 prescaler (BRP bits = 20-1), TSEG2x bits=1,TSEG1x bits = 12. Timequanta = 1+ (1+1) + (12+1) = 16.
Thanks. I did the measurements you suggested and everything looks OK from both sides (outside the CAN driver). But that only tests the TX parts of either end.
So next, I tried the LOOPBACK mode, and realized the receive function isn't reading anything (CANRFLG is always zero). TX is working correctly indicated by the fact that for each message (a 'ping' every half-second), the same TX buffer is used again, and also the oscilloscope showing traffic (when not in LOOPBACK mode).
LOOPBACK mode is supposed to work simply by setting the LOOPB bit in CANCTL1, correct? No other changes are needed. So, if the TX is working what could possibly cause the message not to be received (CANRFLG stays zero)?
Note: Filter is turned off (CANIDAC=%00110000), and CAN mask and ID (CANIDARx and CANIDMRx) are all zeros.
Got it working. Apparently, 'filter closed' means 'filter everything'. Changed to CANIDAC=%00100000, and used all $FF for mask, and it now works.
Thanks.