logo elektroda
logo elektroda
X
logo elektroda

Programming arduino in C in Atmel Studio 7, is that a good idea?

Dzonzi 5082 14
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17015356
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    Hello
    I need to embrace C and avr a bit to pass the labs next semester. I have arduino, I don't think I need to buy a bare atmega and a programmer.
    I have such a program for flashing a diode, but I do not know how to address the PIN for this diode on the board. For now, I want to check if all this will play with me and I want to blink with it.
    So which pin should I type to sweep this diode on the arduino board? So normally this is pin 13, I look at datashit and this is PD7, right?
    Code: C / C++
    Log in, to see the code
  • ADVERTISEMENT
  • #2 17015411
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1460
    The content of your question does not match the topic.
    What is the essence of the question?

    Do you have any problem with STUDIO 7?
  • #3 17015424
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    So it generates hex in stmel studio 7, and then upload it to arduino e.g. with arduino builder, right?

    Added after 11 [minutes]:

    As I thought, I did it and everything is playing and buzzing ;)
    I close.
  • ADVERTISEMENT
  • #4 17015467
    tronics
    Level 38  
    Posts: 5019
    Help: 358
    Rate: 838
    datashit? I would probably understand datasheet, but after 273 posts a friend should know how to express himself in the forum. Mapping pins to the arduino standard is e.g.
    https://www.arduino.cc/en/Hacking/PinMapping168, or you can preview the diagram. So in nano and uno D13 / yellow LED it is PB5, and in Mega it is PB7.
  • #5 17015488
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    Okay, and how is the whole C analog input port from the arduino level, can't it be an input? I understand that now I program it as a regular AVR so I can freely set the I / O? Well, except for PB5, because it has a soldered diode and I can't help it.
  • #6 17015576
    tronics
    Level 38  
    Posts: 5019
    Help: 358
    Rate: 838
    Quote:
    Okay, and how is the whole C analog input port from the arduino level, can't it be an input?

    What about google?
    link
    Probably the second result, in any case with the arduino.cc domain and what are they writing interestingly? Why ask in the forum when the answers are given?
  • ADVERTISEMENT
  • #7 17027436
    marcin w
    Level 22  
    Posts: 756
    Help: 4
    Rate: 81
    I also use the arduino uno board as a ready hardware platform to work with the microcontroller. But programming in atmel studio itself, I upload via usbasp (arduino has such a connector on the board)

    As for the question itself, in AVRs the atmega port consists basically of three registers, each register is 8 bits corresponding to the physical pins of the microcontroller.

    DDRx - direction register, logic 1 on a given bit will set the microcontroller pin as output, logical 0 on a given bit is pin as input
    PORTx - output register
    PINx - input register

    Look at the arduino pinout, PB5 microcontroller (armega328 because I assume you have one) is on the 13th arduino pin.

    PS.
    In an infinite loop, you can achieve the same effect by using bit negation.

    [syntax=c] while(1) {


    PORTB ^= (1
  • #8 17027501
    tronics
    Level 38  
    Posts: 5019
    Help: 358
    Rate: 838
    Quote:
    But programming in atmel studio itself, I upload via usbasp (arduino has such a connector on the board)

    Just for what, you could leave the Arduino bootloader and easily upload via USB programs written in the studio atmel studio without the arduino framework. Even some time ago somewhere on the forum I explained what and how to set up in avrdudess.
  • ADVERTISEMENT
  • #9 17027632
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    I just build the program, then copy the hex code with AS7 and upload it with another program on arduino
  • #10 17027824
    Slawek K.
    Level 35  
    Posts: 3015
    Help: 259
    Rate: 1299
    Just install the Visual Micro for Arduino plugin for ATmel Studio 7 and you have everything from Atmel Studio.
    http://www.visualmicro.com/
    You just need to have Adruino IDE on your disk, it can be portable. The plugin supports the ability to support two versions of the Arduino IDE. You write, upload, etc. - everything with AS7 without a combination with the use of external programs to upload hex. If you connect an arduino, you have the option of software debugging, it is very useful.

    pozdr
    Slawek
  • #11 17027831
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    From what I see at this link, the code is written there in Arduian. Can you write in pure C?
  • #12 17027939
    tronics
    Level 38  
    Posts: 5019
    Help: 358
    Rate: 838
    No ... unfortunately the plugin works by adding a lot of arduino stuff "from a machine" which makes no sense if you don't want to use the framework.
  • #13 17027945
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    What is the point of its installation? People ... I want to program arduino like normal atmege328 in pure C. If I wanted to program like arduino, I would not install AS7, but this native program for uploading on arduino.
  • #14 17027989
    Slawek K.
    Level 35  
    Posts: 3015
    Help: 259
    Rate: 1299
    tronics wrote:
    No...

    Are you sure ?

    pozdr
    Slawek
    Added after 2 [minutes]:
    Dzonzi wrote:
    What is the point of its installation? People ... I want to program arduino like normal atmege328 in pure C. If I wanted to program like arduino, I would not install AS7, but this native program for uploading on arduino.

    Then write what you want and program like an ordinary atmege, what's the problem? ;)

    pozdr
  • #15 17028048
    Dzonzi
    Level 12  
    Posts: 567
    Help: 1
    Rate: 59
    Because I didn't know how to do it

Topic summary

✨ The discussion revolves around programming an Arduino using C in Atmel Studio 7. The original poster seeks guidance on addressing pins for LED control, specifically pin 13, which corresponds to PB5 on the ATmega328 microcontroller. Responses clarify that programming in Atmel Studio allows for direct manipulation of AVR registers (DDRx, PORTx, PINx) and suggest using the Arduino pinout for reference. Some users mention using the Visual Micro plugin for easier integration with Arduino IDE, while others express a desire to program without the Arduino framework, focusing on pure C programming. The conversation highlights the flexibility of using Arduino hardware with traditional AVR programming techniques.
Generated by the language model.

FAQ

TL;DR: Yes—program Arduino Uno in pure C with Atmel Studio 7. ATmega328P runs at 16 MHz; "There is a built-in LED connected to digital pin 13." Build a HEX and upload via USB bootloader or ICSP. [“Arduino UNO Rev3”]

Why it matters: This guides students and hobbyists shifting from Arduino framework to low‑level AVR C without extra hardware.

Quick facts:

  • Uno/Nano LED pin: Arduino D13 maps to PB5; control with DDRB5/PORTB5 in C. [“Pin Mapping 168”]
  • Uno uses ATmega328P @ 16 MHz and offers USB bootloader and a 6‑pin ICSP header. [“Arduino UNO Rev3”]
  • A0–A5 also work as digital I/O (digital 14–19), mapping to PC0–PC5. [“Pin Mapping 168”]
  • Atmel Studio 7 supports C/C++ development for AVR devices using GCC. [“Atmel Studio 7”]
  • Visual Micro plugin adds Arduino upload and debugging inside Atmel Studio. [“Visual Micro for Arduino”]

Quick Facts

  • Uno/Nano LED pin: Arduino D13 maps to PB5; control with DDRB5/PORTB5 in C. [“Pin Mapping 168”]
  • Uno uses ATmega328P @ 16 MHz and offers USB bootloader and a 6‑pin ICSP header. [“Arduino UNO Rev3”]
  • A0–A5 also work as digital I/O (digital 14–19), mapping to PC0–PC5. [“Pin Mapping 168”]
  • Atmel Studio 7 supports C/C++ development for AVR devices using GCC. [“Atmel Studio 7”]
  • Visual Micro plugin adds Arduino upload and debugging inside Atmel Studio. [“Visual Micro for Arduino”]

Is programming an Arduino Uno in pure C with Atmel Studio 7 a good idea?

Yes. You get full control of AVR registers, timing, and memory. Create an AVR GCC C project targeting ATmega328P at 16 MHz. Use Uno’s USB bootloader or ICSP to program the chip. This approach is ideal for coursework and embedded fundamentals. [“Atmel Studio 7”]

Which port/bit controls the onboard LED on Uno or Nano?

On Uno and Nano, Arduino digital pin 13 maps to PB5. In C, set DDRB5 as output, then toggle PORTB5 to blink the LED. "Digital pin 13 is also connected to the LED on the board" applies here. [“Pin Mapping 168”]

How do I build in Atmel Studio 7 and upload over the Arduino bootloader?

  1. Build your AVR C project in Atmel Studio to produce a .hex.
  2. Use avrdude/avrdudess to upload via the board’s COM port (bootloader).
  3. Keep the Arduino bootloader; upload over USB without extra hardware. Users report this workflow works directly. [Elektroda, tronics, post #17027501]

Can I program with USBasp via ICSP instead of the bootloader?

Yes. Connect the 6‑pin ICSP header and program with USBasp or Atmel‑ICE. Using “Upload Using Programmer” bypasses the bootloader and makes serial uploads unavailable until you burn the bootloader again. That is the common Arduino workflow caveat. [“Uploading Using Programmer”]

Can the analog pins be used as digital inputs or outputs in pure C?

Yes. A0–A5 map to PC0–PC5 and correspond to digital pins 14–19. Configure DDRC to set direction, then use PORTC and PINC for writes and reads. This lets you expand available digital I/O without hardware changes. [“Pin Mapping 168”]

Does the LED pin differ on other boards like Mega 2560?

Yes. On Uno/Nano, D13 is PB5. On Mega 2560, D13 maps to PB7. Always check the pin mapping for your specific board to avoid toggling the wrong register bit. [Elektroda, tronics, post #17015467]

Do I need a bare ATmega and a separate programmer to learn AVR C?

No. Uno is a ready hardware platform. It exposes a 6‑pin ICSP header and includes a USB bootloader for uploads. It also features 14 digital I/O and 6 analog inputs, which is ample for labs and practice. [“Arduino UNO Rev3”]

Is Visual Micro required if I want pure C on Atmel Studio 7?

No. Visual Micro injects the Arduino build framework automatically. If you want plain AVR C without Arduino core, skip the plugin and use your own AVR GCC project. [Elektroda, tronics, post #17027939]

What does Visual Micro add if I prefer Arduino APIs inside Atmel Studio?

It integrates Arduino’s build system, board definitions, serial upload, Serial Monitor, and optional debugging into Atmel Studio. This keeps the Arduino programming model while using AS7’s editor and tooling. [“Visual Micro for Arduino”]

What is Arduino Uno?

Arduino Uno is an ATmega328P‑based board running at 16 MHz with USB interface. It provides 14 digital I/O pins and 6 analog inputs. A bootloader enables code uploads over USB without an external programmer. [“Arduino UNO Rev3”]

What is Arduino Nano?

Arduino Nano is a compact ATmega328P board with similar capabilities to Uno in a breadboard‑friendly form. It also has LED on digital 13 and provides convenient USB connectivity for uploads and serial communication. [“Arduino Nano”]

What is USBasp?

USBasp is a low‑cost USB in‑circuit programmer for AVR microcontrollers. It connects to the 6‑pin ICSP header and programs flash and fuses using the ISP protocol from tools like avrdude. [“USBasp - USB programmer for AVR”]

How do I translate Arduino pin numbers to AVR registers quickly?

Use Arduino’s pin‑mapping table. It lists each Arduino pin, its AVR port (e.g., PORTB, PORTC), and bit index. Example: D13→PB5, A0→PC0, A5→PC5. This avoids guessing and prevents register mistakes. [“Pin Mapping 168”]

Can I still use D13/PB5 for general I/O despite the onboard LED?

Yes. D13 is one of Uno’s 14 digital I/O pins. Using PB5 as output will also drive the onboard LED. You can still configure it as input or output like any other digital pin. [“Arduino UNO Rev3”]
Generated by the language model.
ADVERTISEMENT