Getting started with SAMD20E14

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello people, 

I have to develop a project with the ATSAMD20E14 which involves:

- Configure Internall Oscillator as the main clock source for the process. (I'm planning to use the 8MHz internall oscillator from the SAMD20E14)

- Configure External Interrupt (Rising Edge could work)

- Configure I2C module with SERCOM according with the Datasheet

- Configure 2 timers: 

    - 8 bit timer

    - 16 bit timer

- Configure DAC module

- Configure GPIO pins.

 

The problem is that I'm familiar with the Microchip 8bit Microcontrollers and I don't have too much experience with AVR MCUs (I have developed some small projects with ATMEGA164A). So I was wondering if you know some resources or a good way to start getting familiar with the SAMD20E14 MCU.

I was thinking to start with the 8MHz configuration clock and then go with toggling a LED using GPIOs, delays, and next I will go with the rest of all the peripherals that I have to deal with.

Do you know some tutorials to follow or the only way to go with this is through ASF examples? It is a little bit hard to follow the ASF examples as they are not too much descriptive.

Also the other things is that I don't have the hardware in my hands so I will follow my codes through Simulator debugger from Atmel Studio 7.

Thanks, and I will look forward to read some good advices from you guys.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fabianpi wrote:
I was wondering if you know some resources or a good way to start getting familiar with the SAMD20E14 MCU.

1. Get a SAMD20 XPlained-Pro board.

http://www.atmel.com/tools/atsamd20-xpro.aspx

 

2. Get Atmel Studio 7

http://www.atmel.com/microsite/atmel-studio/

http://www.microchip.com/avr-support/atmel-studio-7

 

When you plug the board in, Atmel Studio will recognise it & present you with the list of ready-to-go examples.

 

Atmel has plenty of tutorials - including videos; eg, https://www.youtube.com/watch?v=...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fabianpi wrote:
The problem is that I'm familiar with the Microchip 8bit Microcontrollers and I don't have too much experience with AVR (sic?)  MCUs

Why is that a "problem"?

You must have managed to become familiar with the Microchips - so just adopt the same strategy again!

 

See: http://www.avrfreaks.net/comment...

 

BTW: You do realise that SAM chips are not AVRs - don't you ... ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your reply awneil!

Well, I decided to work with the ASF to develop the code with the "easy to use" library already there.

 

I've doubts about the configuration about the Timers in this case for the following reasons:

1. I'm not sure how to calculate the Timer for this kind of microcontrollers, the ASF example does not show how to calculate a target time, it only shows fixed target times for the example.

 

2. I'm normally use timers setting their value through a register who is the one that counts every cycle and is the that has the correct time steps. In the example this is not occurring, 

it just goes to the "ISR" function where there is executed stuff.

 

3. This is a general doubt about multiple interrupts handling, I'm not sure if you only need to create a function and then it will be your "callback" after been setup in the interrupt configuration or

you have to create a general function to do the interrupt handling.

 

4. I'm also not sure if the clock configuration is correct, I want to only use the internal oscillator for all the peripherals and processes.

 

I will share part of my code to show you my current setup:

 

// 8MHz Internall Oscillator configuration

// This is my setup for the internal oscillator to run with 8MHz as clock source

void clock_init(void)
{
    struct system_clock_source_osc8m_config system_clock;
    system_clock_source_osc8m_get_config_defaults(&system_clock);
    system_clock.on_demand = false; // Run continuously withouth Peripheral calls
    system_clock.prescaler = SYSTEM_OSC8M_DIV_1; // Setting Prescaler to 1 (CONF_CLOCK_OSC8M_PRESCALER)
    system_clock_source_osc8m_set_config(&system_clock);
    //system_clock_source_write_calibration();
    system_clock_init();
}


// Setup for the GCLK generator for the timer peripheral

void conf_gclock_generator(void)
{
    struct system_gclk_gen_config gclock_gen_conf;
    system_gclk_gen_get_config_defaults(&gclock_gen_conf);
    gclock_gen_conf.source_clock = SYSTEM_CLOCK_SOURCE_OSC8M;
    //gclock_gen_conf.division_factor = 128; // default divison_factor: 1
    system_gclk_gen_set_config(GCLK_GENERATOR_1, &gclock_gen_conf);
    system_gclk_gen_enable(GCLK_GENERATOR_1);
}


// Setup for the GCLK Generator channel

void conf_gclock_channel(void)
{
    struct system_gclk_chan_config gclk_chan_conf;
    system_gclk_chan_get_config_defaults(&gclk_chan_conf);
    gclk_chan_conf.source_generator = GCLK_GENERATOR_1;

//#if (SAMD10) || (SAMD11)

//system_gclk_chan_set_config(TC1_GCLK_ID, &gclk_chan_conf);

//system_gclk_chan_enable(TC1_GCLK_ID);

//#else

    system_gclk_chan_set_config(TC3_GCLK_ID, &gclk_chan_conf);
    system_gclk_chan_enable(TC3_GCLK_ID);
//#endif
}


// Now here I have my both timers

// Timer 8bit Setup

// **TODO: We need to test the timers to see if they are working correctly

void tc0_conf(void)
{
    struct tc_config config_tc;
    tc_get_config_defaults(&config_tc);
    config_tc.counter_size = TC_COUNTER_SIZE_8BIT;
    config_tc.clock_source = GCLK_GENERATOR_1;
    config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1024;
    config_tc.counter_8_bit.period = 100;
    config_tc.counter_8_bit.compare_capture_channel[0] = 50;
    //config_tc.counter_8_bit.compare_capture_channel[1] = 54;
    tc_init(&tc_instance, TC3, &config_tc);
    tc_enable(&tc_instance);
    
    // Configure the TC callbacks (Interrupt ISR)
    tc_register_callback(&tc_instance, timer_8bit_ISR, TC_CALLBACK_OVERFLOW);
    tc_register_callback(&tc_instance, timer_8bit_ISR, TC_CALLBACK_CC_CHANNEL0);
    //tc_register_callback(&tc_instance, tc_callback_to_toggle_led,
    //TC_CALLBACK_CC_CHANNEL1);
    
    tc_enable_callback(&tc_instance, TC_CALLBACK_OVERFLOW);
    tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL0);
    //tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL1);
}


// Timer 16bit Setup

void tc1_conf(void)
{
    struct tc_config config_tc2;
    tc_get_config_defaults(&config_tc2);
    config_tc2.counter_size = TC_COUNTER_SIZE_8BIT;
    config_tc2.clock_source = GCLK_GENERATOR_1;
    config_tc2.clock_prescaler = TC_CLOCK_PRESCALER_DIV1024;
    config_tc2.counter_8_bit.period = 100;
    config_tc2.counter_8_bit.compare_capture_channel[0] = 13; // Timer_500ms
    //config_tc.counter_8_bit.compare_capture_channel[0] = 50;
    //config_tc.counter_8_bit.compare_capture_channel[1] = 54;
    tc_init(&tc_instance2, TC3, &config_tc2);
    tc_enable(&tc_instance2);

    // Configure the TC callbacks (Interrupt ISR)
    tc_register_callback(&tc_instance2, timer_16bit_ISR, TC_CALLBACK_OVERFLOW);
    tc_register_callback(&tc_instance2, timer_16bit_ISR, TC_CALLBACK_CC_CHANNEL0);
    //tc_register_callback(&tc_instance, tc_callback_to_toggle_led, TC_CALLBACK_CC_CHANNEL1);

    tc_enable_callback(&tc_instance2, TC_CALLBACK_OVERFLOW);
    tc_enable_callback(&tc_instance2, TC_CALLBACK_CC_CHANNEL0);
    //tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL1);
}

 

The code for the tc0_conf(); and  void tc1_conf() is used to configure:

1. 8bit timer to achieve 1ms callback or ISR Interrupt, this is the one that I'm most sure that is no setup correctly.

2. 8bit timer to achieve 500ms, this one I think is most accurate than the other.

 

I hope to get some help from you guys, thanks!

 

NOTE: I'm sorry but the website is not letting me load the code inside the code style in the forum, so I shared the code not properly

Last Edited: Tue. Nov 7, 2017 - 02:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

fabianpi wrote:
NOTE: I'm sorry but the website is not letting me load the code inside the code style in the forum, so I shared the code not properly

Somewhere in your browser, probably close to top right, there will be a marker saying something to the effect that the site (or page?) tries to load unsecure scripts and the browser has refused. Click the marker and choose to load the scripts anyway. Now the code editor will work.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Tue. Nov 7, 2017 - 02:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

fabianpi wrote:
NOTE: I'm sorry but the website is not letting me load the code inside the code style in the forum, so I shared the code not properly

Somewhere in your browser, probably close to top right, there will be a marker saying something to the effect that the site (or page?) tries to load unsecure scripts and the browser has refused. Click the marker and choose to load the scripts anyway. Now the code editor will work.

Thanks, I fixed now that issue with the website.

 

I'm still don't know how to configure the timers properly in the SAMD20, I feel that the examples from ASF are not too much descriptive.