I would like to establish CAN communication between several STM32 controllers.
The same software runs on each controller, and a DIP switch is used to assign an address to the controller. Depending on the address, the controller should use a different CAN ID to share its performance with the other controllers (the other controllers know who the message is coming from thanks to the CAN ID used).
Unfortunately, I cannot compile the software if the CAN ID of the CAN transmit block depends on a variable. Hence my question:
Is it possible to change the CAN ID depending on a variable? This does not have to happen while the controller is in operation. It would also be sufficient if the controller reads the DIP switch once during initialization, thus knowing its address and determining the CAN ID from it.
Thank you very much for your help and best wishes for Christmas,
I think it may be possible to achieve the desired system behavior by using two separate CAN Transmit blocks with different CAN IDs, setting “Execution” to “Triggered”, and triggering a different block depending on the position of your DIP switch.
If this does not work, may I ask you to attach a PLECS model to help me reproduce the compilation issue?
I also had the idea of using a second CAN transmit block, but unfortunately I get the error message “Only one CAN transmit block for CAN interface 3 supported.” In my setup, I would need a total of 8 transmit blocks, as I can set 8 different addresses via the DIP switch.
You will find my PLECS model in the attachment. When compiling, I get the message: “Signal ‘id1’ must be constant and of integer type.”
I think the easiest way would be to read the address of the DIP switch once when initializing the controller and then assign the CAN ID to this constant value. However, I don’t know how this would be possible.
It looks like you are still working with an old version of the STM32 TSP. Currently, the most recently released version is STM32 TSP 1.5.6, which requires PLECS 4.9.8. The STM32 TSP can be updated under PLECS–>PLECS Preferences…–>Coder or by downloading the STM32 TSP from the Plexim website.
The new version of the TSP includes an overhauled version of the CAN blocks. The old CAN blocks have been deprecated and must be replaced with new CAN blocks in existing PLECS models. We now allow for multiple CAN Transmit blocks using the same CAN interface.