Author Topic: alt func pins for the ATSAM21E15B  (Read 973 times)

0 Members and 1 Guest are viewing this topic.

Offline drakejestTopic starter

  • Regular Contributor
  • *
  • Posts: 200
  • Country: 00
alt func pins for the ATSAM21E15B
« on: June 29, 2021, 07:22:38 pm »


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 datasheet



I 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 appreciated

I 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,
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2733
  • Country: us
Re: alt func pins for the ATSAM21E15B
« Reply #1 on: June 29, 2021, 09:37:44 pm »
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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11763
  • Country: us
    • Personal site
Re: alt func pins for the ATSAM21E15B
« Reply #2 on: June 29, 2021, 09:50:55 pm »
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.
Alex
 

Offline drakejestTopic starter

  • Regular Contributor
  • *
  • Posts: 200
  • Country: 00
Re: alt func pins for the ATSAM21E15B
« Reply #3 on: June 30, 2021, 06:43:11 am »
So help me correct if im wrong

usb n - pin 23
usb p - pin 24

ADC
- pin 4 (vrefa)
- pin 5 (vrefb)
- pin 6,7,8,9,11,12,13,14

JTAG
- SWDIO pin 32
- SWDCLK pin 31

I could not find SPI and PWM pins though.
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2733
  • Country: us
Re: alt func pins for the ATSAM21E15B
« Reply #4 on: June 30, 2021, 02:43:02 pm »
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[2]' or 'TCC3/WO[0]', 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[2]' 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.
 
The following users thanked this post: drakejest

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11763
  • Country: us
    • Personal site
Re: alt func pins for the ATSAM21E15B
« Reply #5 on: June 30, 2021, 03:29:53 pm »
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.
Alex
 

Offline drakejestTopic starter

  • Regular Contributor
  • *
  • Posts: 200
  • Country: 00
Re: alt func pins for the ATSAM21E15B
« Reply #6 on: June 30, 2021, 04:09:50 pm »
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[2]' or 'TCC3/WO[0]', 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[2]' 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.

Thank 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 applications

So 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[PAD0] - MOSI
PA17[PAD1] - SCLK
PA18[PAD2] - CS
PA19[PAD3] - MISO

please 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 100kH

the safe option is to follow what the arduino(nano 33 iot) uses that are available to me. but only 2 are available in my skew

PA04 - TCC0
PA05 - TCC0

I could not decide , there are alot of things i dot understan  |O :-DD


Can i just really pick 1 of each ?
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11763
  • Country: us
    • Personal site
Re: alt func pins for the ATSAM21E15B
« Reply #7 on: June 30, 2021, 04:46:06 pm »
please do correct me if i messing up assigning the said pins.
This SPI assignment is correct.

Can i just really pick 1 of each ?
There 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.
Alex
 
The following users thanked this post: drakejest

Offline drakejestTopic starter

  • Regular Contributor
  • *
  • Posts: 200
  • Country: 00
Re: alt func pins for the ATSAM21E15B
« Reply #8 on: June 30, 2021, 05:15:55 pm »
There 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.

That is indeed might become a problem, i will have to turn to 3rd party libraries or beg someone to make them for me  :-DD knowing how bad i am at registry manipulations

Theoretically 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.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11763
  • Country: us
    • Personal site
Re: alt func pins for the ATSAM21E15B
« Reply #9 on: June 30, 2021, 05:33:13 pm »
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.
Alex
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2733
  • Country: us
Re: alt func pins for the ATSAM21E15B
« Reply #10 on: June 30, 2021, 05:39:22 pm »
Theoretically 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.
Actually 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: [Select]
#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: [Select]
void startTcc(Tcc* timer){
    timer->CTRLA.reg |= TCC_CTRLA_ENABLE;
}

Which you can then use like:
Code: [Select]
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).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf