Can I create a new serial port on the Arduino Uno to run a Simulink model in real time that also uses a serial port?

16 Ansichten (letzte 30 Tage)
I'm attempting to run the example MODBUS RS485 Communication Between Client and Server Using Arduino Board with two Arduino Uno units. These units have only one dedicated serial port on pins 0 and 1. When I go to Monitor and Tune the Client Model, I get an error message for all 6 MODBUS blocks in the model that reads:
Error evaluating 'InitFcn' callback of codertarget.arduinobase.internal.arduino_ModbusRS485MasterRead block (mask) 'arduino_modbus_client/Modbus RS485 Client Read'.
Callback string is 'codertarget.arduinobase.conflictcheck.validateandregisterBlocks(gcbh);'
Caused by:
The SerialPin_1 '1' being used by 'arduino_modbus_client/Modbus RS485 Client Read' is currently in use by 'Monitor and tune over XCP on Serial'. To resolve the conflict, change the value of SerialPin_1 in 'arduino_modbus_client/Modbus RS485 Client Read' to an alternate valid value.
It appears that the only port the Arduino Uno has is in use by the USB interface with my desktop computer. I know that ArduinoIDE has the SoftwareSerial library addon that is supposed to allow you to assign pins to create a separate serial port, but I don't know if a similar operation is possible in Simulink. Or perhaps I can create the new port in ArduinoIDE for use in the Simulink model. Thank you.

Akzeptierte Antwort

surya venu
surya venu am 13 Jun. 2024
Hi,
Your issue arises because the Arduino Uno's primary hardware serial port (Serial) is being used for both the USB communication with your computer and for MODBUS RS485 communication in your project. This creates a conflict, especially when you're trying to use the same serial port for monitoring and tuning your Simulink model via the USB connection.
Simulink models for Arduino typically use the hardware serial port for deploying and debugging the model, which is why you're encountering the error. To work around this, you're correct in thinking about "SoftwareSerial", a library that allows you to create a software-based serial port on almost any digital pins of the Arduino.
Unfortunately, Simulink does not directly support "SoftwareSerial" within its block set for Arduino. However, you can integrate custom code, including "SoftwareSerial", into your Simulink model. This involves writing some parts of your model's logic in C++ and ensuring it interacts correctly with the rest of your Simulink model.
The above link contains information about:
  • Create Project and Libraries Folder
  • Write Hardware Specific C/C++ Code
  • Select System Object Template
  • Specify Initialization, Output, and Termination Behavior
  • Update Paths for Source and Header Files
  • Set Output Port Properties Create
  • MATLAB System Block
  • Generate Code and Deploy Model to Hardware
Hope it helps.
  1 Kommentar
Gavin Trevorrow
Gavin Trevorrow am 13 Jun. 2024
Thank you for your insight! It looks like the page you linked to will be a good starting point for creating the custom code necessary to assign new pins and create the port.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by