Home

Last Modified: 21 November 2000

6172 CAN Micro Controller Module AN007


This application example is not yet completely tested

This example shows a typical RS232 application, using a MAX232 to convert RXD/TXD data signals and RTS/CTS handshake signals from 5V CMOS level to ±9V RS232 level.


Schematic diagram

 


Sequence assembler source code

No sequence is needed with this application, unless the user also wants to implement a DTR/DSR handshake signal (like in the 6390). These signals can be connected to the 6172 in/outputs and an appropriate sequence has to be started on memory read or write.


CANopen object dictionary configuration

Assuming that all 6172 objects are in their default state, the following objects can be adjusted (if PDOs are used):

 

Index

Subindex

Value

Description

Use receive PDO1 to send one character via 6172 RS232 output

1600h

0

1

1 object in receive PDO 1

1600h

1

20310008h

object 2031h, subindex 0, 8 bits

Use receive PDO2 to send one up to seven characters via 6172 RS232 output

1601h

0

2

1 object in receive PDO 2

1601h

1

20300040h

object 2030h, subindex 0, 64 (40h) bits

Use transmit PDO 1 to read one character from 6172 receive buffer (reads zero when no character received)

1A00h

0

1

1 object in transmit PDO 1

1A00h

1

20350008h

object 2035h, subindex 0, 8 bits

Use transmit PDO 2 to read up to seven characters from 6172 receive buffer

1A01h

0

1

1 object in transmit PDO 2

1A02h

1

20340040h

object 2034h, subindex 0, 64 (40h) bits


NOTE: when reading/writing object 2034/2030 via a PDO: at least 2 bytes should be assigned to the object in the PDO.
See note in 6172 object dictionary for further information


Example BASIC program

Copy and Paste this part direct after the declarations in the canappl.bas program
this program can be found on the 6197 designers kit diskette or
ordered separately as service part together with one of our CAN products.  

APPLICATION:
 
'This simple program is made for one 6172 and a 6390 as CAN bus interface
'the following assumptions are done:
'- 6390 is connected to COM2
'- 6172 ID = 1, CANbus speed = 50 kBAUD
'- assembled sequence file is "AN007.seq"
 
'- this program displays two 'windows'. 
'- any typed character will be shown in the upper window and will be transmitted
'  via the RS232 output
'  Any received character will be shown in the lower window.
'- the program ends when 'ESC' is pressed
 
CLS
PRINT "CD Systems 6172 AN007 DEMO program"
PRINT
 
Activate6390 2, 19200                          '6390 works at COM2, 19200 BAUD
SetCANBUSSpeed 50                                         'CAN BUS at 50 kBAUD
 
C% = CheckSequence%(1, "AN007.seq")     'download sequence if not already done
 
C% = PutU8%  (1, &h1600, 0, 1)          '1 object in receive PDO 1
C% = PutU32% (1, &h1600, 1, &h20310008) 'receive PDO 1 to transmit one char
C% = PutU8%  (1, &h1601, 0, 1)          '1 object in receive PDO 2
C% = PutU32% (1, &h1601, 1, &h20300040) 'receive PDO 2 to transmit 1-7 char
C% = PutU8%  (1, &h1A00, 0, 1)          '1 object in transmit PDO 1
C% = PutU32% (1, &h1A00, 1, &h20350008) 'transmit PDO 1 to receive one char
C% = PutU8%  (1, &h1A01, 0, 1)          '1 object in transmit PDO 2
C% = PutU32% (1, &h1A01, 1, &h20340040) 'transmit PDO 2 to receive 1-7 char
 
SendNMTCommand (1, 1)                   'node in operational state
 
RPDO1COB% = (1 +  512) * 32                           'receive  PDO1 COB ID 
TPDO2COB% = (1 +  640) * 32                           'transmit PDO2 COB ID 
 
DIM SCR$(2, 9)                        'table holds upper/lower screen contents
DIM H%(2), V%(2)                      'cursor positions
 
'display 2 windows on screen, clear SCR$ (78 spaces/index)
 
SPC$ = STRING$(78, 32)
CLS : PRINT "6172 Micro Controller Module demo program, AN007"
PRINT
 
FOR W% = 1 TO 2
  H%(W%) = 1: V%(W%) = 1
  PRINT CHR$(218); STRING$(78, 196); CHR$(191);
  FOR L% = 1 TO 9
    PRINT CHR$(179); SPC$; CHR$(179);
    SCR$(W%, L%) = SPC$
  NEXT L%
  PRINT CHR$(192); STRING$(78, 196); CHR$(217);
NEXT W%
LOCATE 3, 20: PRINT " Transmit window "
LOCATE 14, 20: PRINT " Receive window "
 
DO
  'Display any pressed key in upper window and send it with receive PDO1
  C$ = INKEY$
  IF C$ <> "" THEN
     IF C$ = CHR$(27) THEN GOTO ENDPROG
     W% = 1: GOSUB DISPLAY
     SendToCAN (CANIDS$(TPDO1COB%)) + C$)
  END IF
 
  'Check if transmit PDO2 received, display 1-7 chars in lower window if so
  R$ = ReceiveFromCAN$
 
  IF (LEN (R$) > 3) AND (CANIDR%(R$) = TPDO2COB%) THEN
     FOR I% = 1 TO ASC (MID$(R$,3))                    'amount of char
       C$ = MID$(R$, I% + 3, 1)  
       W% = 2: GOSUB DISPLAY
     NEXT I%
  END IF
LOOP UNTIL 1 = 0
 
ENDPROG:
 
SendNMTCommand (1, 2)                             'stop node
 
END
 
'---------------------------------------------------------------------
'Subroutines called with GOSUB keep them in the QBASIC main window....
 
'Display C$ in upper or lower window (according to W%)
 
DISPLAY:
 IF C$ = CHR$(13) GOTO NXTLINE
 IF C$ < CHR$(32) THEN RETURN
 
 MID$(SCR$(W%, V%(W%)), H%(W%)) = C$
 
 LOCATE W% * 11 - 8 + V%(W%), 2: PRINT SCR$(W%, V%(W%));
 
 H%(W%) = H%(W%) + 1: IF H%(W%) < 79 THEN RETURN
 
NXTLINE:
 H%(W%) = 1:
 IF V%(W%) < 9 THEN V%(W%) = V%(W%) + 1: RETURN
 
'scroll display, clear last line
 FOR T% = 1 TO 9
   IF T% = 9 THEN SCR$(W%, T%) = SPC$ ELSE SCR$(W%, T%) = SCR$(W%, T% + 1)
   LOCATE W% * 11 - 8 + T%, 2: PRINT SCR$(W%, T%);
 NEXT T%
RETURN
 
END