alt func pins for the ATSAM21E15B - Page 1
Forum section: electronics / projects

author: drakejest
author_rank: Regular Contributor
timestamp: June 29, 2021, 07:22:38 pm
content: So I am attempting to replicate the samd21 of the arduino nano 33 Iot circuit for my own project, problem is that specific chip is out of stock everywhere so i have to make do with its cousin the ATSAM21E15B. I believe they all work the same considering they share data sheets.My problem is because they all share 1 data sheet i could not figure out what pins are the alt function that i need. all i see is the pinout for my package from this massively overwhelming datasheetI am specifically looking for the native USB, SPI, and JTAG pins, PWM, and ADC of my specific chip. if someone well versed of the atsamd21 can help me it would be greatly appreciatedI chose this series because its realativly easy to start with, it basically need no more than a few components to get it running, just a couple of capacitors,

author: ajb
author_rank: Super Contributor
timestamp: June 29, 2021, 09:37:44 pm
content: The alternate functions for the pins are given in the pin multiplexing section of the datasheet, should be just after the part where you found that diagram iirc.

author: ataradov
author_rank: Super Contributor
timestamp: June 29, 2021, 09:50:55 pm
content: Yes, scroll down a few pages from those drawings there will be a big table with all the alternate functions. The pin drawings are not that useful on their own.

author: drakejest
author_rank: Regular Contributor
timestamp: June 30, 2021, 06:43:11 am
content: So help me correct if im wrongusb n - pin 23usb p - pin 24ADC- pin 4 (vrefa)- pin 5 (vrefb)- pin 6,7,8,9,11,12,13,14JTAG- SWDIO pin 32- SWDCLK pin 31I could not find SPI and PWM pins though.

author: ajb
author_rank: Super Contributor
timestamp: June 30, 2021, 02:43:02 pm
content: PWM is available on the timer pins. The SAM D series has two different types of timers, "Timer/Counters" and "Timer/Counter for Control Applications". These are labeled TCn and TCCn, where 'n' is the timer number. TCC timers have more features that make them better for controlling power stages (for motors or switching converters) than TC timers, but both can be used for basic PWM. TC timers have two waveform outputs and can do two PWM channels per timer, TCC timers have eight waveform outputs and can do four PWM channels per timer (the extra waveform outputs are usually used to provide complementary PWM outputs, like for controlling an H bridge with separate high and low side drive signals). The waveform outputs are labeled like 'TC5/WO' or 'TCC3/WO', where the first part is the timer and the bracketed number is the waveform output. The two timer types have their own sections in the datasheet that will explain how to use their various features.SPI is available through the SERCOM peripherals. Rather than having separate SPI, USART, and I2C peripherals, the SAM D series uses one SERCOM peripheral that can do all three of those. This is actually one of my favorite features of this MCU family because it makes the parts very flexible and tends to make PCB layout easier. Each SERCOM has four IO pads, which can be used for different signals in different modes. There is a section in the datasheet for each SERCOM mode, so if you look at the "SERCOM SPI" section it will explain how to use it. Under the SERCOM SPI section, look at the Control A register in the Register Description section. The DIPO and DOPO bit fields control how the SPI signals are assigned to IO pads, and the tables for them will show what signals can be used on which pad. Like with the timers, the SERCOM pin functions are labeled like 'SERCOM4/PAD' where the bracketed number is the pad number.Since you said you're replicated an Arduino that used a different SAMD21, do you actually need to worry about all of this? Depending on which SAMD21 is used in the Arduino you're replicating the only difference may be the memory size, all of the libraries for SPI, PWM, etc might just work and you can go by the pin assignments the arduino thing offers.

author: ataradov
author_rank: Super Contributor
timestamp: June 30, 2021, 03:29:53 pm
content: It is much easier to think about pin compatibility in terms of actual port numbers. USB will be PA24/PA25 on all device. So you need to lookup the functionality you need on the old device, and use the same exact pin names, and match them to the pin numbers on the new device.

author: drakejest
author_rank: Regular Contributor
timestamp: June 30, 2021, 04:09:50 pm
content: Quote from: ajb on June 30, 2021, 02:43:02 pmThank you for clearing some things up, since the time i have posted i have learned quite a few stuff. i might be worrying over nothing but i wwould like to use the best pins for my applicationsSo as for sercom, it looks like i will be using sercom1 as sercom0 are also analog in pins which i will be needing and sercom 2 is not present on my specific skew.PA16 - MOSIPA17 - SCLKPA18 - CSPA19 - MISOplease do correct me if i messing up assigning the said pins.My last problem and i think my biggest hurdle is choosing the pwm pins, i need 4 of them, my best case scenario is for them to have different clock source so that they wont be schynchronied, seems straight forward choose a pins with different timer TCC0, TCC1, TCC2, TCC3 . and i need to be able to change the frequency of atleast 100kHthe safe option is to follow what the arduino(nano 33 iot) uses that are available to me. but only 2 are available in my skewPA04 - TCC0PA05 - TCC0I could not decide , there are alot of things i dot understanCan i just really pick 1 of each ?

author: ataradov
author_rank: Super Contributor
timestamp: June 30, 2021, 04:46:06 pm
content: Quote from: drakejest on June 30, 2021, 04:09:50 pmThis SPI assignment is correct.Quote from: drakejest on June 30, 2021, 04:09:50 pmThere is some sort of a TC or TCC function available on almost every pin. A bigger question is how flexible standard Arduino drivers. The worst case scenario is that you will have to make your own drivers.Also, you don't always need VREFA/VREFB and you most likely don't need them both at the same time.

author: drakejest
author_rank: Regular Contributor
timestamp: June 30, 2021, 05:15:55 pm
content: Quote from: ataradov on June 30, 2021, 04:46:06 pmThat is indeed might become a problem, i will have to turn to 3rd party libraries or beg someone to make them for meknowing how bad i am at registry manipulationsTheoretically i only need 3 functions, to set the frequency, to change the duty cycle , and stoping and starting. I believe each timer would need their ow version of the function.

author: ataradov
author_rank: Super Contributor
timestamp: June 30, 2021, 05:33:13 pm
content: If you don't need them to look like full-blown Arduino C++ drivers, then basic code for PWMs is very simple, it is just a few lines of code.

author: ajb
author_rank: Super Contributor
timestamp: June 30, 2021, 05:39:22 pm
content: Quote from: drakejest on June 30, 2021, 05:15:55 pmActually no, you could create start/stop/duty cycle functions that take the timer as an argument. This is one of the nice things about more modern MCUs versus older ones like the AVRs, the header files that define the peripheral registers are more structured and make it easier to abstract these things. When you reference, for example, TCC0 in your code, "TCC0" is defined as a pointer to that timer's set of registers, here's how it's defined for the SAMD21:Code:#define TCC0 ((Tcc *)0x42002000UL) /**< \brief (TCC0) APB Base Address */Here, the number in hex is the address where the first TCC0 register is located, and the `(Tcc *)` part turns the address into a pointer to a "Tcc" struct, which defines how the registers are mapped. This means that you can pass "TCC0" as an argument to a function like:Code:void startTcc(Tcc* timer){timer->CTRLA.reg |= TCC_CTRLA_ENABLE;}Which you can then use like:Code:startTcc(TCC0);startTcc(TCC1);You would still need to use separate functions for TCC and TC peripherals since they have different register sets (well there's a way to do one function for both but it's a bit messy).