Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

CAN-bus library for general CAN-bus controller chip MCP2515
Goto page Previous  1, 2
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Thu Feb 06, 2020 10:57 pm    Post subject: Reply with quote

Hi Per,

It seems to me, You do not use INT pin (from MCP2515). Is that correct?

BR
Andrej
Back to top
View user's profile
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 238
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Fri Feb 07, 2020 9:48 am    Post subject: Reply with quote

Hi Andro,

Yes I skipped the INT pin and use register polling instead.
SPI is so fast so I decided not to use interrupt.
But it is of course easy to let DataReady generate an interrupt, if that better suits the application.
Perhaps we should let a compiler directive select between hard INT or soft polling?

/Per
Back to top
View user's profile Visit poster's website
andro

Bascom Member



Joined: 12 Mar 2007
Posts: 94
Location: Ljubljana

slovenia.gif
PostPosted: Fri Feb 07, 2020 1:05 pm    Post subject: Reply with quote

That would be a major change of the concept. First I would start as it is - without INT / ISR handling.
I already prepared some HW
BR
A
Back to top
View user's profile
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Fri Feb 14, 2020 11:02 pm    Post subject: Baud Rate Register Values Reply with quote

I noticed that the values being written to the baud rate registers do not match those shown in the calculation table above the code.
In particular, CNF1 @ 250K and 500K do not match. They may have been swapped.
Back to top
View user's profile
Per Svensson

Bascom Member



Joined: 03 Oct 2004
Posts: 238
Location: Gothenburg, Sweden

sweden.gif
PostPosted: Tue Feb 18, 2020 1:48 pm    Post subject: Reply with quote

Hi rkumetz

Yes there was a typing error in the CASE for 250 and 500 kbit/s
The table was right however. I double-checked it against Kvasers's baudrate calculator.
Here is the correct CASE table:

Select Case Baudrate 'kbit/s
Case 10 : Cnf1 = &H27 : Cnf2 = &HBF : Cnf3 = &H2
Case 20 : Cnf1 = &H13 : Cnf2 = &HBF : Cnf3 = &H2
Case 50 : Cnf1 = &H09 : Cnf2 = &HB5 : Cnf3 = &H1
Case 125 : Cnf1 = &H03 : Cnf2 = &HB5 : Cnf3 = &H1
Case 250 : Cnf1 = &H03 : Cnf2 = &H91 : Cnf3 = &H1 '<- Corrected Feb.18 2020
Case 500 : Cnf1 = &H00 : Cnf2 = &HB5 : Cnf3 = &H1 '<- Corrected Feb.18 2020
Case 800 : Cnf1 = &H00 : Cnf2 = &H9A : Cnf3 = &H1
Case 1000 : Cnf1 = &H00 : Cnf2 = &H91 : Cnf3 = &H1
Case Else : Can_baud = 1 : Exit Function 'Error (ignore new baud)
End Select

How many people have tried this CAN-implementation? Is would be interesting to know.
Just wave hand, or give a short comment here if you have the time...

/Per
Back to top
View user's profile Visit poster's website
rkumetz

Bascom Member



Joined: 23 Jan 2007
Posts: 165
Location: Vermont

usa.gif
PostPosted: Tue Feb 18, 2020 3:06 pm    Post subject: Reply with quote

Thanks for double checking. I looked at the values in the comment table and corrected them but
since I am new to CAN I wanted to make sure that I was not making a mistake somewhere.

This code is super helpful. I started out with the MCP2517 and then found that there are apparently
some odd "quirks" such as an unstable oscillator so I switched to the pin compatible MCP2518.
For my simple application I found that the '2518 was horribly complex compared to the '2515 and
the added functionality did not outweigh the extra time to get it going. There is also virtually little
information out there about the 2518 which makes finding examples tough. I bought an MikroElektronika
"Click" board and hand wired it to the pads for the MCP2518. In an hour I was way ahead
of where I started out.

Thanks again!
Back to top
View user's profile
Memen

Bascom Member



Joined: 06 May 2016
Posts: 13

blank.gif
PostPosted: Fri Oct 23, 2020 4:59 pm    Post subject: Reply with quote

Connected to listen to the bus at 500 kbps. I get the only result after turning it on.

Got: ID=09C7A785h Extended=1 INT=10100001 STATUS=00000000 HIT=0 FILTER=0 ROLLOVER=1 SOURCE=0 N=82 RxData: 239 248 165 127 239 22 53 167 0 0 0 12 186 159 251 78 155 231 236 118 141 173 59 90 0 0 0 240 169 56 244 82 239 248 165 127 239 22 53 167 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 57 32 50 50 32 53
Back to top
View user's profile AIM Address
boeseturbo

Bascom Member



Joined: 23 Jul 2007
Posts: 65

blank.gif
PostPosted: Thu Jul 04, 2024 11:41 am    Post subject: Reply with quote

Hi,

had anybody tried to use filter and masks? For me, its not working. I want to filter id 7DF. When I use this as filter and mask it accept all packages Sad

Can anybody help?

Cheers
Back to top
View user's profile
kasny.ondrej

Bascom Member



Joined: 03 Feb 2024
Posts: 59

czechrepublic.gif
PostPosted: Mon Aug 05, 2024 5:37 pm    Post subject: Reply with quote

Sucesfully readed CANOpen values from servo Lenze 8400 topline. But needed a few modifications. First of all for testing purposes I bought CAN SPI module. Sad thing was 8MHz crystal on it.



Autobaud function did not worked on Lenze. It was not able to match baudrate on ongoing CAN talking between other devices. Then default setting it on 125kHz and it looked similary like Memen's results. So hardcoded it to 500kHz did the job along with baud table modification.
So I hade to change baud table to:
Code:
'The table below is assuming that XTAL=8MHz
 'See: https://www.kvaser.com/support/calculators/bit-timing-calculator/
'     T1 T2 BTQ SP% SJW BAUD ERR% CNF1 CNF2 CNF3
'10:  17  3  20  85   1   10  0    13   bf   02
'20:  17  3  20  85   1   20  0    09   bf   02
'50:  14  2  16  87.5 1   50  0    04   b5   01
'125: 14  2  16  87.5 1  125  0    01   b5   01
'250:  6  2  8   75   1  250  0    01   91   01
'500:  6  2  8   75   1  500  0    00   91   01
'800:  3  2  5   60   1  800  0    00   80   01


' for 1000 baudrate 8MHz crystal is slow
Things I noticed:
Applying filter mask does not do anything becouse of 2 things.
1st:

Code:
Sub Can_receive_options(byval Filter As Byte , Byval Rollover As Byte)
'Receiver options, common to both receive buffers
'Turn all receive filtering and buffer-rollover ON/OFF
'FILTER:   0=OFF, 1=ON
'ROLLOVER: 0=OFF, 1=ON

   If Filter = 1 Then
      Filter = &B00000000                                                                 'ON
   Else
      Filter = &B01100000                                                                 'OFF (Accept all messages)
   End If

   Filter.bukt = Rollover                                                                 'ROLLOVER
   Mcp2515_bitmodify Rxb0ctrl , &B01100100 , Filter

End Sub

this is still off. Activation function calling is missing.
2nd:
Code:
Case "M" :
         Stop Watchdog
         Input "RFX MASK nr.(0 or 1): " , I                                               'Filter number
         If I > 1 Then
            Print "Ignored - No such Mask!"
         Else
            Inputhex "ID MASK (hex 0..1FFFFFFF: " , Dw1                                   'ID-MASK  (DWORD)
            If Dw1 > &H1FFF_FFFF Then
               Print "Ignored - ID too high!"
            Else
               Errcode = Can_filter_setup(i , Dw1 )
            End If
         End If
         Start Watchdog
 


mask setup IMHO should call: Can_mask_setup but is calling Can_filter_setup

Otherwise it sucesfully after some tuning works on atxtiny3217, but next step would be AVR128DA48. Just noticed strange behaviour with SPI on xtiny3217:
Code:

Config Spi0 = Hard , Clockdiv = Clk16 , Data_order = Msb , Mode = 0 , Master = Yes , Ss = None


SS must be set None and then CS controlled manually like it is in original code. Leaving on auto causes high/low glitching at start of transmision on CS line and then nothing is readed from SPI. Sending into MCP2515 but nothing recieving. When controled manually works like a charm. No problem with Auto on W5500 chip. Maybe MCP2515 is more sensitive.

Many thanks to author who wrote this it. I leaarned so much again.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum