Use other pins for SAMD21 DMX

LXSeries open source projects are hosted on github.
Post Reply
admin
Site Admin
Posts: 1643
Joined: Mon Nov 05, 2007 1:26 am
Contact:

Use other pins for SAMD21 DMX

Post by admin »

For an open source project called NittyGritty (a ‘swiss knife for sound artists�) with an Arduino MKRzero I use your LXSAMD21DMX.h library to drive a DMX system. It uses the default sercom 4 macros but my Port on Pin 4 is already taken (by a rotary encoder) and I cannot change the PCB’s. How can I change PIN_DMX_TX? When I change it from (4ul) to (1ul) -preferrable- or (6ul) it doesn’t work on these Pins.
admin
Site Admin
Posts: 1643
Joined: Mon Nov 05, 2007 1:26 am
Contact:

Post by admin »

The SAMD21 has a variety of pin/sercom options.  If you want details you can look them up in the table in the datasheet.  There are several pre-built options in the header file that are set by defining a macro.  The documentation starts at line 461.  The macro that selects the options is defined on line 497.  It is commented out by default.  However, you can un-comment it and define the use_optional_sercom_macros to one of the three alternate pin configurations.  Some boards/projects/libraries use one or more of the SERCOM modules.  (A notable example is Serial)  So, in addition to avoiding pin conflicts, you also want to choose a SERCOM that is not in use for something else.
The header file has a URL for an article by Adafruit that explains SERCOMs and how they are configured.  I'd look at that if you want more information.  You can dig how it works out of the datasheet.  But, that can be confusing and the Adafruit article makes it simple and clear.  https://learn.adafruit.com/using-atsamd ... xing-it-up
admin
Site Admin
Posts: 1643
Joined: Mon Nov 05, 2007 1:26 am
Contact:

Post by admin »

To be clear, you cannot just change the pin definitions. All of the other macros must also change. So, to use pin 1 for DMX output, in the header you would uncomment line 497 and it would read:

#define use_optional_sercom_macros 3

The definition (or lack thereof) of use_optional_sercom_macros controls the conditional compilation that sets the pins, SERCOM, and handler function pointer to make the library work with different serial outputs.

Note: The header contains a fifth option to use pins 13 and 14 which was added but left out of the instructions. This is fixed in the latest commit. So, the line to uncomment for use_optional_sercom_macros is now 498.

I believe that you'll be successful by just defining use_optional_sercom_macros and picking one of the alternate sets of pins that are pre-configured.
Post Reply