0

I am newbie in programming the microcontroller. I would like to test the micro by blinking the LED in a pin. The micro is SAMR35J18B and I am using ATMEL ICE programmer and ATMEL studio software for the programming. I am able to detect the micro in the software but I could not find proper program to blink the LED. I tried few and did not work out. The pin PB02 is connected to LED through a transistor. I will attach the code which i used. Could someone tell me what is wrong with the program or please attach a link for a basic LED blink program. Thank you.

#include "sam.h"

int main(void)
{
    unsigned int i;

    /* Initialize the SAM system */
    SystemInit();
    REG_PORT_DIR0 |= 1<<2;

    /* Replace with your application code */
    while (1) 
    {
        REG_PORT_OUTTGL0 = PORT_PB02;
      
        for (i=0;i<100000;i++)
        {
        }
    }
}
winny
  • 13,064
  • 6
  • 46
  • 63
  • 3
    Does the LED turn on? If you really expect it to blink, then where are you turning it off? – kkrambo Sep 28 '21 at 14:29
  • 3
    HOW did it not work? Saying "it does not work" tells us nothing. – DKNguyen Sep 28 '21 at 14:39
  • There are quite a few issues with your code, but the biggest issue is you haven't included everything necessary for initialization. Atmel studio hides a lot of stuff from you. And I have no idea if you've set up the project correctly. That SystemInit() function is automatically generated by A-Studio based on your specifications (clock source & speed, peripherals, IO usage, etc). Atmel SAM chips are not a good place to start unless you are already familiar with microcontrollers. You'll need to search the START projects for a blink program for your MCU/board. – Kurt E. Clothier Sep 28 '21 at 18:49
  • So are you using a custom board? The Module? The Xplained evaluation board? – Kurt E. Clothier Sep 28 '21 at 18:55
  • @KurtE.Clothier I am not using custom board. I have assembled MC directly on to the pcb and have necessary pins to connect to programmer. I have just selected the MC name and included this above program which i found in the internet. – Manjesh Gowda Sep 29 '21 at 07:53
  • @kkrambo LED did not turn on. becuase there was not enough voltage in the PB02 pin to acivate the gate of the transistor which turns on the LED. This code did not give any error and I was able to flash this code on to MC. I am not sure whats wrong – Manjesh Gowda Sep 29 '21 at 07:55
  • How is the transitors connected externally? DO you have a schematic? I'm voting to close as there is not enough info to solve your problem. – Kurt E. Clothier Oct 01 '21 at 15:25
  • Start with Arduino, and then graduate to a book on Embedded C Programming for Beginners, using a particular evaluation board like one of the [XPlained boards previously mentioned.](https://www.digikey.com/en/products/filter/evaluation-boards-embedded-mcu-dsp/786?s=N4IgjCBcoLQExVAYygFwE4FcCmAaEA9lANogCsIAugL7X4KSkAaACgDYCGAlgHbYAmIfAGcOAWyr4AbIhBdBkEDDAAGCPgAOqKCCEhUATw3YdHYSlpA) I apologize, but we're not going to teach you C programming for a board you made yourself. Take yourself to "school" first, **then** come to us with the book and the board and with a schematic. Then we can answer. – MicroservicesOnDDD Oct 26 '21 at 18:05

0 Answers0