$regfile = "m8def.dat" $crystal = 4000000 $baud = 9600 $dbg 'Config Spi = Hard , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1 Config Spi = Soft , Din = Portb.3 , Dout = Portb.5 , Ss = None , Clock = Portb.5 Config Pinb.1 = Output Enable Interrupts Enable Spi Dim Cmd(3) As Byte Dim Adresse As Byte Dim S As String * 8 Dim Daten As Byte Dim A As Byte Dim X As Byte Const Canread = &H03 Const Canreset = &HC0 Const Canstatus = &HA0 Const Canrxstatus = &HB0 Const Canwrite = &H02 Const Canctrl = &H0F Declare Sub Setcsl() Declare Sub Setcsh() Declare Sub Can_write() Declare Sub Can_read_byte() Spiinit Waitms 300 Print "Can Testprogramm" Cmd(1) = Canwrite Cmd(2) = Canctrl Cmd(3) = &B10000000 Call Can_write() 'config mode Waitms 200 Cmd(3) = &HE0 Call Can_write() 'loopback Do Cmd(1) = Canread Cmd(2) = Canstatus Call Can_read_byte() 'statusbyte S = Bin(daten) Print "Statusbyte : " ; S Wait 1 Cmd(2) = Canctrl Call Can_read_byte() S = Bin(daten) Print "Registerinhalt : " ; S Wait 2 Loop '____________________________________________________________________________ Sub Setcsh() 'ss or cs high Set Portb.1 Waitms 10 Print "H" End Sub Sub Setcsl() Reset Portb.1 Waitms 10 Print "L" End Sub Sub Can_write() Setcsl Waitms 10 Spiout Cmd(1) , 3 Setcsh End Sub Sub Can_read_byte() Setcsl Waitms 10 Spiout Cmd(1) , 2 Waitms 10 Spiin Daten , 1 Waitms 60 Setcsh End Sub