@@ -7,15 +7,12 @@ to connect the pyboard to a CAN bus you must use a CAN transceiver
77to convert the CAN logic signals from the pyboard to the correct
88voltage levels on the bus.
99
10- Note that this driver does not yet support filter configuration
11- (it defaults to a single filter that lets through all messages),
12- or bus timing configuration (except for setting the prescaler).
13-
1410Example usage (works without anything connected)::
1511
1612 from pyb import CAN
17- can = pyb.CAN(1, pyb.CAN.LOOPBACK)
18- can.send('message!', 123) # send message to id 123
13+ can = CAN(1, CAN.LOOPBACK)
14+ can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126)) # set a filter to receive messages with id=123, 124, 125 and 126
15+ can.send('message!', 123) # send a message with id 123
1916 can.recv(0) # receive message on FIFO 0
2017
2118
@@ -35,7 +32,17 @@ Constructors
3532 - ``CAN(1) `` is on ``YA ``: ``(RX, TX) = (Y3, Y4) = (PB8, PB9) ``
3633 - ``CAN(2) `` is on ``YB ``: ``(RX, TX) = (Y5, Y6) = (PB12, PB13) ``
3734
38-
35+ Class Methods
36+ -------------
37+ .. method :: CAN.initfilterbanks(nr)
38+
39+ Reset and disable all filter banks and assign how many banks should be available for CAN(1).
40+
41+ STM32F405 has 28 filter banks that are shared between the two available CAN bus controllers.
42+ This function configures how many filter banks should be assigned to each. ``nr `` is the number of banks
43+ that will be assigned to CAN(1), the rest of the 28 are assigned to CAN(2).
44+ At boot, 14 banks are assigned to each controller.
45+
3946Methods
4047-------
4148
@@ -75,6 +82,37 @@ Methods
7582
7683 Turn off the CAN bus.
7784
85+ .. method :: can.setfilter(bank, mode, fifo, params)
86+
87+ Configure a filter bank:
88+
89+ - ``bank `` is the filter bank that is to be configured.
90+ - ``mode `` is the mode the filter should operate in.
91+ - ``fifo `` is which fifo (0 or 1) a message should be stored in, if it is accepted by this filter.
92+ - ``params `` is an array of values the defines the filter. The contents of the array depends on the ``mode `` argument.
93+
94+ +-----------+---------------------------------------------------------+
95+ | ``mode`` |contents of parameter array |
96+ +===========+=========================================================+
97+ | CAN.LIST16 |Four 16 bit ids that will be accepted |
98+ +-----------+---------------------------------------------------------+
99+ | CAN.LIST32 |Two 32 bit ids that will be accepted |
100+ +-----------+---------------------------------------------------------+
101+ | CAN.MASK16 |Two 16 bit id/mask pairs. E.g. (1, 3, 4, 4) |
102+ | | | The first pair, 1 and 3 will accept all ids |
103+ | | | that have bit 0 = 1 and bit 1 = 0. |
104+ | | | The second pair, 4 and 4, will accept all ids |
105+ | | | that have bit 2 = 1. |
106+ +-----------+---------------------------------------------------------+
107+ | CAN.MASK32 |As with CAN.MASK16 but with only one 32 bit id/mask pair.|
108+ +-----------+---------------------------------------------------------+
109+
110+ .. method :: can.clearfilter(bank)
111+
112+ Clear and disables a filter bank:
113+
114+ - ``bank `` is the filter bank that is to be cleared.
115+
78116.. method :: can.any(fifo)
79117
80118 Return ``True `` if any message waiting on the FIFO, else ``False ``.
@@ -98,7 +136,6 @@ Methods
98136
99137 Return value: ``None ``.
100138
101-
102139Constants
103140---------
104141
@@ -108,3 +145,10 @@ Constants
108145.. data :: CAN.SILENT_LOOPBACK
109146
110147 the mode of the CAN bus
148+
149+ .. data :: CAN.LIST16
150+ .. data :: CAN.MASK16
151+ .. data :: CAN.LIST32
152+ .. data :: CAN.MASK32
153+
154+ the operation mode of a filter
0 commit comments