Forum: Mikrocontroller und Digitale Elektronik ATMega16M1 CAN wo landen die empfangenen Daten?


von Thomas (kosmos)


Lesenswert?

Nachdem die Übertragung selbst nun funktioniert, die CAN Nachricht als 
empfangen wird und ein ACK gesendet wird. Verzweifle ich daran an die 
Daten zu kommen.

Es gibt ja 6 MOBs die man mittels CANPage auswählt, wie liest man nun 
aber den Identifier und die Daten aus, wenn man das ganze nicht per 
Maske ausfiltert sondern jede Nachricht verwerten will.

Spielt mir da der FIFO CAN Date Buffer einen streich weil dieser 
weiterhochzählt.

Ich habe mal den Code etwas ausgekürzt (Stackpointer, 
Portinitialisierung, Interruptvektortabelle...weggekürzt)

Das Programm verbleibt einfach in einer Schleife und bei einem Interrupt 
soll einfach das 1 Byte (0b00000001 oder 0b00000000) ausgewertet werden 
und per LED angezeigt werden.
1
CAN_init:
2
ldi temp, (0<<ABRQ)|(0<<OVRQ)|(0<<TTC)|(0<<SYNTTC)|(0<<LISTEN)|(0<<TEST)|(0<<ENASTB)|(1<<SWRES)
3
sts CANGCON, temp    ; CAN General Control Register,   software reset
4
ldi temp, (0<<ABRQ)|(0<<OVRQ)|(0<<TTC)|(0<<SYNTTC)|(0<<LISTEN)|(0<<TEST)|(1<<ENASTB)|(0<<SWRES)
5
sts CANGCON, temp    ; CAN General Control Register,   software reset
6
7
Ready_enable:
8
lds temp, CANGSTA
9
sbrs  temp, ENFG    ;CAN enable
10
rjmp  Ready_enable  ;springt raus, wenn fertig
11
12
ldi temp, (0<<BRP5)|(0<<BRP4)|(1<<BRP3)|(0<<BRP2)|(0<<BRP1) |(1<<BRP0)
13
sts CANBT1, temp    ; set baud rate to 16 kbps bei Stystem Clock 8 Mhz
14
ldi temp, (1<<PRS2)|(1<<PRS1)|(1<<PRS0)
15
sts CANBT2, temp
16
ldi temp, (1<<PHS22)|(1<<PHS21)|(1<<PHS20)|(1<<PHS12)|(1<<PHS11)|(1<<PHS10)|(1<<SMP)
17
sts CANBT3,temp
18
19
ldi temp, (0<<MOBNB3)|(0<<MOBNB2)|(0<<MOBNB1)|(1<<MOBNB0)|(0<<AINC)|(0<<INDX2)|(0<<INDX1)|(0<<INDX0)
20
sts CANPAGE, temp    ; select MOb0
21
22
lds temp, CANSTMOB
23
ldi temp, 0
24
sts CANSTMOB, temp    ; CAN Statusregister löschen
25
26
ldi temp, (1<<ENIT)|(0<<ENBOFF)|(1<<ENRX)|(0<<ENTX)|(0<<ENERR)|(0<<ENBX)|(0<<ENERG)|(0<<ENOVRT)
27
sts CANGIE, temp    ; enable Interrupts
28
29
ldi temp, (1<<CANIT)|(0<<BOFFIT)|(0<<OVRTIM)|(0<<BXOK)|(0<<SERG)|(0<<CERG)|(0<<FERG)|(0<<AERG)
30
sts CANGIT, temp
31
32
ldi temp, (0<<ENMOB5)|(0<<ENMOB4)|(0<<ENMOB3)|(0<<ENMOB2)|(0<<ENMOB1)|(0<<ENMOB0)
33
sts CANEN2, temp    ; enable MOB
34
35
ldi temp, 0b00000000
36
sts CANEN1, temp    ; reserved
37
38
ldi temp, (0<<IEMOB5)|(0<<IEMOB4)|(0<<IEMOB3)|(0<<IEMOB2)|(0<<IEMOB1)|(1<<IEMOB0)
39
sts CANIE2, temp
40
41
ldi temp, 0b00000000
42
sts CANIE1, temp    ; reserved
43
44
ldi temp, (0<<SIT5)|(0<<SIT4)|(0<<SIT3)|(0<<SIT2)|(0<<SIT1)|(0<<SIT0)
45
sts CANSIT2, temp    ; enable CAN Status Interrupt
46
47
;ldi temp,(0<<TPRSC7)|(0<<TPRSC6)|(0<<TPRSC5)|(0<<TPRSC4)|(0<<TPRSC3)|(0<<TPRSC2)|(0<<TPRSC1)|(0<<TPRSC0)
48
;sts CANTCON,temp    ; CAN timer Prescaler
49
50
;ldi temp,(0<<HPMOB3)|(0<<HPMOB2)|(0<<HPMOB1)|(0<<HPMOB0)|(0<<CGP3)|(0<<CGP2)|(0<<CGP1)|(0<<CGP0)
51
;sts CANHPMOB,temp    ; CAN Highest Priority MOb Register
52
53
init_CAN_Identifier_Maske:  ;Filter deaktivieren, alle Nachrichten werden verarbeitet
54
ldi temp, 0
55
sts CANIDM1, temp
56
sts CANIDM2, temp
57
sts CANIDM3, temp      ;nur nötig bei 29bit ID
58
sts CANIDM4, temp
59
60
ldi temp,(1<<CONMOB1)|(0<<CONMOB0)|(0<<RPLV)|(0<<IDE)|(0<<DLC3)|(0<<DLC2)|(0<<DLC1)|(1<<DLC0)
61
sts CANCDMOB, temp    ; RX Mode enable, CAN 11bit identifier, 8bit data lenght muss vor CANGCON übermittelt werden
62
63
ldi temp, (0<<ABRQ)|(0<<OVRQ)|(0<<TTC)|(0<<SYNTTC)|(0<<LISTEN)|(0<<TEST)|(1<<ENASTB)|(0<<SWRES)
64
sts CANGCON, temp    ; CAN General Control Register,   software reset
65
66
loop: rjmp loop
67
68
CAN_INT:
69
lds temp, CANMSG
70
cpi temp, 0
71
breq LED_aus
72
rjmp LED_an
73
74
LED_an:
75
ldi temp, 0b10000000  ;Pin7 Ausgang für LED
76
out portd, temp
77
reti
78
79
LED_aus:
80
ldi temp, 0b010000000  ;Pin7 Ausgang für LED
81
out portd, temp
82
reti

von Rudolph R. (rudolph)


Lesenswert?

Keine Ahnung was der Code macht, das tue ich mir nicht an.

Aber, erstmal steht im CANSIT2 Register drin, welche Message-Box den 
Interrupt ausgelöst hat.
Entsprechend wird über das CANPAGE Register die Message-Box ausgewählt.
Und dann findet man über die CANIDTn Register raus welche ID die 
empfangene Botschaft hat.

Bits 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 – IDTn: Identifier Tag
Identifier field of the remote or data frame to send. This field is 
updated with the corresponding value of
the remote or data frame received.

Wenn man denn weiss wohin das soll, kann man die Botschaft über das 
CANMSG Register auslesen.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.