Direct access to micro controller registers

Hi Guys,

I have a general question about ARDUINO programming: is there a way to directly access the micro controller's registers that are on the ARDUINO board using the ARDUINO IDE?

I mean that in general, and not just concerning the IO registers.

Thanks
Udi

Which register(s) would you like to access ?

I would like at first to access the sleep register (MCUCR), but I believe I might need to access some other registers as I go on. Is there a general way to access these registers?

udilevy:
Hi Guys,

I have a general question about ARDUINO programming: is there a way to directly access the micro controller's registers that are on the ARDUINO board using the ARDUINO IDE?

I mean that in general, and not just concerning the IO registers.

Which Arduino board?
Which microcontroller?

When it comes to direct register programming each microcontroller is different.

And direct register programming with 32-bit conrollers is much more complicated than with 8-bit Atmega controllers.

I'm using the ARDUINO UNO board, but as I said my question is more general, as I'm used to programming microcontrollers that are not ARDUINO based - using IAR or Keil IDEs, there are usually examples and headers enabling write to MCU registers, here's an example to configuring register in IAR code:

//TIM1_Pulse = CCR3_Val
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
duty, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_RESET);

Are there similar code examples in ARDUINO IDE?

AFAIK all of the Atmel registers are accessible in Arduino code by the names used in the Atmel datasheets.

...R

Thanks Robin, do you know ifd there is an example code for the sleep register of the arduino uno mcu (MCUCR)

udilevy:
I'm using the ARDUINO UNO board, but as I said my question is more general, as I'm used to programming microcontrollers that are not ARDUINO based - using IAR or Keil IDEs, there are usually examples and headers enabling write to MCU registers, here's an example to configuring register in IAR code:

//TIM1_Pulse = CCR3_Val
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE,
duty, TIM1_OCPOLARITY_LOW, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_RESET);

Are there similar code examples in ARDUINO IDE?

The Arduino software is based on "AVR GCC", so all programming examples for Atmega controllers and AVR GCC should work directly in the Arduino IDE, too.

As a first step, perhaps have a look at:

Perhaps also look up the pin mapping between the PINx/PORTx and genuine Arduino pin numbering.

On the Arduino oard you find pins numbered 0, 1, 2, 3, 4, 5... but actually those pins belong to PORT register (i.e. PORTD on an UNO board with Atmega328) and each pin is mapped to a bit within the PORT register.

In general you can use any tutorial for Atmega controllers written for AVR GCC compiler learning about direct register programming, example code also works in the Arduino IDE.

That's great! I'll give it a try and see how it works.

For me these examples were extremely valuable: Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors.