logo elektroda
logo elektroda
X
logo elektroda

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

Dzonzi 4515 14
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17015356
    Dzonzi
    Level 12  
    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
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 17015411
    JacekCz
    Level 42  
    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  
    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.
  • #4 17015467
    tronics
    Level 38  
    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.
  • ADVERTISEMENT
  • #5 17015488
    Dzonzi
    Level 12  
    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.
  • ADVERTISEMENT
  • #6 17015576
    tronics
    Level 38  
    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?
  • #7 17027436
    marcin w
    Level 22  
    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  
    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.
  • #9 17027632
    Dzonzi
    Level 12  
    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  
    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  
    From what I see at this link, the code is written there in Arduian. Can you write in pure C?
  • ADVERTISEMENT
  • #12 17027939
    tronics
    Level 38  
    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  
    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  
    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  
    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.
Summary generated by the language model.
ADVERTISEMENT