View Full Version : Can Bus
geardown
04-19-03, 09:53 AM
Where can I find the documentation and drivers for the Can
The project I am working on I need to be able to Tx and Rx
Thank You
blueeyedpop
06-13-03, 01:02 AM
Just got CANBUS working on the IsoPod ( also works with IsoPod-mini and ServoPod.
This is my first working stab at it. Upload the same code to the transmitter and receiver. Run TYPEM on one, and XRX or XRX2 on the other. Thanks to Randy at NMI for the flags, constants and speed setup.
I have a "centipede" I am working on, and plan on using 6 IsoPod Minis on it, to make wiring easier. http://www.bio-bot.com/movies
( -----------------------------------------------------------------------------------------
SCRUB ( CLEARS THE MEMORY
HEX
( CAN REG D80 DFF
D80 CONSTANT CANCTL0 EEWORD
D81 CONSTANT CANCTL1 EEWORD
D84 CONSTANT CANRFLG EEWORD
D86 CONSTANT CANTFLG EEWORD
: RXF? CANRFLG @ 1 AND ; EEWORD
: RXCLR 1 CANRFLG ! ; EEWORD
: TXE? CANTFLG @ 7 AND ; EEWORD
: TX0E? CANTFLG @ 1 AND ; EEWORD
: TX1E? CANTFLG @ 2 AND ; EEWORD
: TX2E? CANTFLG @ 4 AND ; EEWORD
: TX0 1 CANTFLG ! ; EEWORD
: TX1 2 CANTFLG ! ; EEWORD
: TX2 4 CANTFLG ! ; EEWORD
: RX RXF?
IF
DC4 DCC @ DUMP ." " DCC @ . ." BYTES " RXCLR
THEN ; EEWORD
: RX2 RXF?
IF
DC4 DCC @ TYPE RXCLR
THEN ; EEWORD
: LOOPBACK ( USE AFT INIT
1 D80 ! ( SOFT RESET
D81 @ 4 OR D81 ! ( SET LOOPBACK
0 D80 ! ( END SOFT RESET
; EEWORD
: INIT
1 D80 ! ( SOFT RESET
80 D81 ! ( MSCAN ON, EXTAL CLK
( 81 D81 ! ( MSCAN ON, IP CLK
01 D82 ! ( 0 SYNC, 2 PRESCALE
23 D83 ! ( 500K CLK
( 00 D88 ! ( 2 32BIT FILTER
10 D88 ! ( 4 16BIT FILTER
( 20 D88 ! ( 8 8BIT FILTER
( 30 D88 ! ( FILTER CLOSED
( The two zeros at byte 2, bit 4-5, are RTR and IDE
( If you set IDE it means you want 29 bit ID's
( If you transmit a 1 for RTR, it means it is a data requast message
( and carries no real data. This is a real gotcha!
(
( Filter 0 1000 XXXX XXX0 0XXX
( Filter 1 0100 XXXX XXX0 0XXX
( Filter 2 0010 XXXX XXX0 0XXX
( Filter 3 0001 XXXX XXX0 0XXX
( MASK REGISTERS 1=DON'T CARE
( BOTTOM 3 BITS MUST BE SET ON 16 BIT MASK
( ACCEPTANCE REG, RX'D VALUE = REGISTER
( FILTER 0
0F D94 ! ( CANIDMR0
E7 D95 ! ( CANIDMR1
80 D90 ! ( CANIDAR0
00 D91 ! ( CANIDAR1
( FILTER 1
0F D96 ! ( CANIDMR2
E7 D97 ! ( CANIDMR3
40 D92 ! ( CANIDAR2
00 D93 ! ( CANIDAR3
( FILTER 2
0F D9C ! ( CANIDMR4
E7 D9D ! ( CANIDMR5
20 D98 ! ( CANIDAR4
00 D99 ! ( CANIDAR5
( FILTER 3
0F D9E ! ( CANIDMR6
E7 D9F ! ( CANIDMR7
10 D9A ! ( CANIDAR6
00 D9B ! ( CANIDAR7
0 D80 ! ( RELEASE RESET
; EEWORD
: L D80 80 DUMP ; EEWORD ( DUMP ALL CAN REGISTERS
: XRX BEGIN RX ?TERMINAL UNTIL ; EEWORD
: XRX2 BEGIN RX2 ?TERMINAL UNTIL ; EEWORD
( FILTER-X-HIT SEND A PRE-SET MESSAGE TO A PARTICULAR
( FILTER
: FILTER-0-HIT
80 DD0 ! 00 DD1 ! 00 DD2 ! 00 DD3 !
46 DD4 ! ( MESSAGE F
49 DD5 ! ( MESSAGE I
4C DD6 ! ( MESSAGE L
54 DD7 ! ( MESSAGE T
45 DD8 ! ( MESSAGE E
52 DD9 ! ( MESSAGE R
20 DDA ! ( MESSAGE
30 DDB ! ( MESSAGE 0
8 DDC !
TX0
; EEWORD
: FILTER-1-HIT
40 DD0 ! 00 DD1 ! 00 DD2 ! 00 DD3 !
46 DD4 ! ( MESSAGE F
49 DD5 ! ( MESSAGE I
4C DD6 ! ( MESSAGE L
54 DD7 ! ( MESSAGE T
45 DD8 ! ( MESSAGE E
52 DD9 ! ( MESSAGE R
20 DDA ! ( MESSAGE
31 DDB ! ( MESSAGE 1
8 DDC !
TX0
; EEWORD
: FILTER-2-HIT
20 DD0 ! 00 DD1 ! 00 DD2 ! 00 DD3 !
46 DD4 ! ( MESSAGE F
49 DD5 ! ( MESSAGE I
4C DD6 ! ( MESSAGE L
54 DD7 ! ( MESSAGE T
45 DD8 ! ( MESSAGE E
52 DD9 ! ( MESSAGE R
20 DDA ! ( MESSAGE
32 DDB ! ( MESSAGE 2
8 DDC !
TX0
; EEWORD
: FILTER-3-HIT
10 DD0 ! 00 DD1 ! 00 DD2 ! 00 DD3 !
46 DD4 ! ( MESSAGE F
49 DD5 ! ( MESSAGE I
4C DD6 ! ( MESSAGE L
54 DD7 ! ( MESSAGE T
45 DD8 ! ( MESSAGE E
52 DD9 ! ( MESSAGE R
20 DDA ! ( MESSAGE
33 DDB ! ( MESSAGE 3
8 DDC !
TX0
; EEWORD
VARIABLE EMM 8 ALLOT EEWORD
VARIABLE LEN EEWORD
VARIABLE XIT EEWORD
VARIABLE ID 4 ALLOT EEWORD
( FILTER-X PRE SET THE FILTER TO USE WITH TYPEM
( USE XRX OR XRX2 TO RECIEVE THE MESSAGE
: FILTER-0
80 ID ! 00 ID 1 + ! 00 ID 2 + ! 00 ID 3 + !
; EEWORD
: FILTER-1
40 ID ! 00 ID 1 + ! 00 ID 2 + ! 00 ID 3 + !
; EEWORD
: FILTER-2
20 ID ! 00 ID 1 + ! 00 ID 2 + ! 00 ID 3 + !
; EEWORD
: FILTER-3
10 ID ! 00 ID 1 + ! 00 ID 2 + ! 00 ID 3 + !
; EEWORD
: M
ID DD0 4 CMOVE>
( 0 DD0 ! 0 DD1 ! 1F DD2 ! FE DD3 ! ( ALL BITS IN ID, DATA FORMAT
EMM DD4 LEN @ CMOVE> LEN @ DDC !
TX0
; EEWORD
: TYPEM
0 XIT !
BEGIN
8 0 DO
I 1+ LEN !
KEY DUP 1B = IF 1 XIT ! LEAVE
ELSE
I EMM + !
THEN
LOOP
M XIT @ UNTIL ; EEWORD
INIT
( XRX TO RECEIVE
( FILTER-0-HIT OR FILTER-1-HIT OR FILTER-2-HIT OR FILTER-3-HIT
( TO TRANSMIT
( OR FILTER-X TO SET ID
( AND THEN TYPEM
Thanks Blueeyedpop!
It is nice to see somebody tackling a problem that is beyond my current and limited ability with ISOMAX.
I am trying to learn in my spare time but it is a bit off and on.
Is it perhaps too much to ask if you can post a "learner" version that has detailed step-by-step explanations? I am sure it will be well received by others too.
CANBUS is something I like to learn more about given its speed etc. so any guidance is appreciated.
I like the ISOPODs and hope that NMI will include details about the CANBUS and programming samples in future documentation.
Cheers from the Norse
blueeyedpop
07-29-03, 11:12 PM
I will try later, but right now I am truly slammed.
One thing to consider for CANBUS, is that the way CAN unburdens itself from having to read all of the messages on the bus, is to use what are called filters and acceptance registers.
The acceptance reg. basicly says which bits you care about, and which you do not. THe filter then accepts the messages whose bit patterns match the bits you actually care about.
hopefully more later
Thank you!
Perhaps you can first make a short note about setting the Mask Registers for 16 bit filters...
I assume some of the Hex numbers below the filter comments are the values.
I looked at the binary bit pattern but I am not sure how they are used in light of 2 bytes needed for each filter.
The first thing I aim for is the ability to send PWM values to three or 4 motors controlled by ISOPODS and NMI PWM drivers. I have set up a basic joystick control for 2 motors on one ISOPOD. I am pleased with the NMI's H-Bridge as it gives me lots of power and smooth control.
I look forward to your future postings and will study your code in the meantime....
Cheers.
blueeyedpop
07-30-03, 12:30 PM
To follow this, you really need the DSP56F801-7UM/D manual.
It's been a while since I wrote the code, but...
- ------------------------------------
10 D88 ! ( 4 16BIT FILTER
This sets up for four 16 bit filters.
With 16 bit filters, there are a couple of bits which are specific to certain types of comms, the IDE bit and the RTR bit.
The IDE bit set to 0 means we are using 11bit identifiers as opposed to 29 bit identifiers.
The RTR is remote transmission request. Look for this bit, if you want to operate in a polled mode. I am not sure of the details, but if you set this bit in a package you send, then you do not send any data with it.
------------------------------------
( MASK REGISTERS 1=DON'T CARE
( BOTTOM 3 BITS MUST BE SET ON 16 BIT MASK
( ACCEPTANCE REG, RX'D VALUE = REGISTER
( FILTER 0
0F D94 ! ( CANIDMR0 Mask register 0
E7 D95 ! ( CANIDMR1 Mask register 1
80 D90 ! ( CANIDAR0 Acceptance register 0
00 D91 ! ( CANIDAR1 Acceptance register 1
so for the first filter, filter 0, we do 0F D94 !
which puts 0000,1111 into the top 16 bits of the mask register, which correspond to ID10 to ID containing 0's which means we want to look at them, and ID6 to ID3 to 1, which means we do not care what their value is.
E7 D95 ! sets ID2 to ID0 to 1, and sets RTR to 0 and IDE to 0, with the remaining bits set to one.
if you break it up by bytes, you have 0FE7 brake that into binary, and you have 0000 1111 1110 0111
which correspond to (ID10-ID7) (ID6-ID3) (ID2-ID0,RTR) and finally (IDE,DEFAULT 111) see fig8-26 in the manual.
So this code sets us up to only look at ID10-ID7, if you look at the settings for the four filters, you will see the mask registers all have the same values.
Next, the filter registers look somethinf like this:
8000 for Filter 0
4000 for Filter 1
2000 for Filter 2
1000 for Filter 3
I have set just one bit for each filter, but they bit I set falls within the opening of the mask I set.
TRANSMISSION:
Re visiting the manual and my code, I may have found a mistake.
if you look at C56 in the programmers notes, I think the following note in mu code should have read:
: FILTER-0-HIT
08 DD0 ! 00 DD1 ! 00 DD2 ! 00 DD3 ! ( not 80 DD0 !
46 DD4 ! ( MESSAGE F
49 DD5 ! ( MESSAGE I
4C DD6 ! ( MESSAGE L
54 DD7 ! ( MESSAGE T
45 DD8 ! ( MESSAGE E
52 DD9 ! ( MESSAGE R
20 DDA ! ( MESSAGE
30 DDB ! ( MESSAGE 0
8 DDC !
TX0
; EEWORD
and the other identifiers chould be 04 DD0 ! 02 DD0 ! and 01 DD0 ! etc.
In any case, this is how you would transmit a message.
DD0 to DD3 set the bits for the identifier for the message, and DDC is the data length.
hope this helps, sorry for the typo
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.