Hello,
I have to send a 8 Byte Message by CAN-Bus.
My programm is running well with 4 Byte, but not with 8 Byte.
8 Byte are 64Bit, so I set the variable for sending (it´s called "Wert") from Dword to Double.
But this doesn´t work, because it sends everything else, but not the value I want.
For example I send &H3F, but I receive an other value (see attached picture).
Can anyone take a look on the code and help me?
Thank you very much!
Roland
This is my code:
[code:1:193a99f9db]
$regfile = "m128can.dat" ' processor we use
$crystal = 16000000 ' Crystal 16 MHz
$hwstack = 64
$swstack = 32
$framesize = 40
$prog &HFF , &HFF , &HB9 , &HFF ' generated. Take care that the chip supports all fuse bytes.
'------------------------------------------------------------------------------
'-------------------- Deklarationen -------------------------
'------------------------------------------------------------------------------
Dim _can_page As Byte , _canid As Dword , _can_int_idx As Byte , _can_mobints As Word
Dim Breceived As Byte , Bok As Byte , Bdil As Byte , Wert As Double
'------------------------------------------------------------------------------
'-------------------- Konfigurationen -------------------------
'------------------------------------------------------------------------------
On Canit Can_int
Enable Interrupts
Canreset ' reset can controller
Canclearallmobs ' clear alle message objects
Canbaud = 500000 ' use 125 KB
Config Canbusmode = Enabled ' enabled,standby,listening
Config Canmob = 0 , Bitlen = 11 , Idtag = &H0120 , Idmask = &H0120 , Msgobject = Receive , Msglen = 1 , Autoreply = Disabled 'first mob is used for receiving data
Config Canmob = 1 , Bitlen = 11 , Idtag = &H0120 , Msgobject = Disabled , Msglen = 8 ' this mob is used for sending data
Cangie = &B10111000 ' CAN GENERAL INTERRUPT and TX and RX
Wert = &H3F
'------------------------------------------------------------------------------
'-------------------- Hauptprogramm -------------------------
'------------------------------------------------------------------------------
Do
Bok = Cansend(1 , Wert , 8)
Loop
'------------------------------------------------------------------------------
'-------------------- Subroutinen -------------------------
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'-------------------- Interruptroutinen -------------------------
'------------------------------------------------------------------------------
'*********************** CAN CONTROLLER INTERRUPT ROUTINE **********************
'multiple objects can generate an interrupt
Can_int:
_can_page = Canpage ' save can page because the main program can access the page too
Cangetints ' read all the interrupts into variable _can_mobints
For _can_int_idx = 0 To 14 ' for all message objects
If _can_mobints._can_int_idx = 1 Then ' if this message caused an interrupt
Canselpage _can_int_idx ' select message object
If Canstmob.5 = 1 Then ' we received a frame
_canid = Canid() ' read the identifier
Breceived = Canreceive(porta) ' read the data and store in PORTA
Config Canmob = -1 , Bitlen = 11 , Msgobject = Receive , Msglen = 1 , Autoreply = Disabled , Clearmob = No ' reconfig with value -1 for the current MOB and do not set ID and MASK
Elseif Canstmob.6 = 1 Then 'transmission ready
Config Canmob = -1 , Bitlen = 11 , Msgobject = Disabled , Msglen = 8 , Clearmob = No ' reconfig with value -1 for the current MOB and do not set ID and MASK
End If
End If
Next
Cansit1 = 0 : Cansit2 = 0 : Cangit = Cangit ' clear interrupt flags
Canpage = _can_page ' restore page
Return
[/code:1:193a99f9db]
[b:193a99f9db][color=red:193a99f9db](BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.6 )[/b:193a99f9db][/color:193a99f9db]
↧