SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions about processor boards have here!
#240510
Dear all,
I ordered some SAMD21 Mini Breakout DEV-13664 to test them with a shield I originally designed for the Arduino Pro Mini 8Mhz, 3.3V.
In the underlying application for which I designed the shield PCB, I needed one additional serial port.
So, when I designed the shield for the original Pro Mini, using D9 for TX and D8 for RX appeared to me being the best option because this way it is possible to use both libraries SoftwareSerial and AltSoftSerial (on the Pro Mini, AltSoftSerial is restricted to TX on D9 and RX on D8).

Now, I wanted to check my options to replace the Pro Mini by the SAMD21 Mini Breakout DEV-13664 and actually everthing should work, only the additional serial port I need on D9 and D8 appears to be problematic.
Well, I already learned that the widely used libraries for a software emulated serial (i.a. SoftwareSerial and AltSoftSerial) ara not compatible with the SAMD21 Mini Breakout DEV-13664.
In principle, however, this would not be a problem as the SAMD21G offers several SERCOMS to create additional hardware serial ports which is better anyway. But now looking a bit deeper into that I found the information that "... you cannot have TX on pad 1 or pad 3... " in a guide from Adafruit (https://learn.adafruit.com/using-atsamd ... new-serial).


Now, unfortunately D9 just happens to be just pad 3 (SER0:3), wheras D8 is pad 2 (SER0:2)
Image

You see, the problem is that my shield is using exactly the D9 pin as TX and according to my current understanding this means that if there is no other way to get the D9 working as TX using the SAMD21G, I would have to adopt my shield's PCB design to change that. As far as I understand, I could e.g. just swap the pins to make D9 act as RX and D8 as TX... However, doing so the drawback would then be that such redesigned new shields would then not work with the Arduino Pro Mini and the ALTSoftSerial any more... only with the Pro Mini + SoftwareSerial...

So, my question is now if there is really no possibility to use D9 as TX for a serial via SERCOM?
I mean, is this a hardware limitation of the ATSAMD21G or is this something which has to do with the Arduino libraries (i.a. variants.cpp, variants.h, sercom.h or wiring_private.h)?
If it is a software imposed limitation, how could I circumvent that?

Thank's a lot for your suggestions and support!

Best,
Michael
#240516
No, you can not circumvent it.

The input and output pads of the 6 SERCOMS can be assigned to a number of pads/pins from the processor. In the case of SAMD21 Mini, the board pins labeled D8 and D9 are connected to the processor on PA06 and PA07.

There are 2 issues :
D9 is connected to PA07, which can only be assigned as PAD[3] for SERCOM0. However in the SAM21D datasheet, table 25.1, TX can only be assigned to PAD[0] and PAD[2] (as you already know). There is no way around this.

If you look at the SAM21D datasheet (pag 21), PA06 and PA07 can only be assigned to SERCOM0. This SERCOM0 is already in use for Serial1 but then assigned to PA10 and PA11, which are connected to the D1 and D0 board pins. This one COULD be solved with software changes, but it will not help given issue 1.

Maybe the best way forward is to have a jumper or soldering pad on your add-on board to select.
#240573
As I adjusted a Sofwareserial before I decided to see whether I could create one for the SAM21D. The biggest challenge was a stable timer and timing. Attached is a version that works on my QWIIC Micro SAMD21 developer board.

I use pins 5 and 6, but I expect pins 8 and 9 will work as well. It worked stable up to 57600 baud. Although sending COULD be 115200 but that is pushing the limit. The lower the speed the better however........

Maybe this helps you.. and look forward to your feedback.

For installation see the readme in the zip.
You do not have the required permissions to view the files attached to this post.
#240639
Wow,
thank you Paul for your support!
I will give it a try and report...

In the meanwhile, I also found this one: https://github.com/meelyn-pandit/Softwa ... wareSerial
With this library I already got serial working on D9 (TX) and D8(RX)...

So far, I have not compared your library and the one above from Meelyn into depth...
In case you know this lib from Meelyn, or you should be interested yourself anyway, maybe you could have a glance and give me some comments about the mayor differences between your and the SS lib from Meelyn? As I have to decide which one I should take and would go for the one which is more reliable and has all the functions I need, your feedback on that would be highly appreciated... ;-)

At this moment I would probably prefer yours, because yousay that have already tested that it works until 57600 baud, which is enough for my application. Also yours is better commented....
On the other hand the one from Meelyn appears to have also a .stoplistening implemented which could be interesting for me...

However, at the moment I don't understand yet if I could use .stoplistening to stop interrupts from SS.
In my application the device receives a command from a master via the emulated serial port and is then performing a certain task according to that command. So this means, received that command, I would prefer to avoid further interrupts from RX, because I don't want the interrupts from SS to interfere with other processes (communication, counting, etc...) of the task. After that the device should send a reply to the master and start listening again...

So one question to you here: do you know if I could do this with the .stoplistening () function in the lib from Meelyn, or would it be better to use .end () anyway, which is also implemented in your SS?

Thank you very much!
#240641
Thanks for pointing that out. I had looked on GitHub before I started but did not find this link.

While the working outcome is the same, the approach is a little different. The major difference is how timing is implemented for TX and RX: they use delaymicroseconds() and wait, while my approach uses timer TC4 and interrupts. Both of them should work and you can check which is better for you.

Do not use end() in my version, it will reset the timer configuration but use .stoplistening().
That was declared private, but I have moved that to public so you can use it from the sketch now.
Attached is the updated version and I will update the GitHub link as well.
You do not have the required permissions to view the files attached to this post.
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum