Go Down

Topic: Write register values in code (Read 1 time) previous topic - next topic

vorkiej

How can I directly write a register value in my code?

For example the PWM_CMR_CPOL (0x1u << 9) change the register value 0 to 1.

Code: [Select]
// This doesn't work
#define PWM_CMR_CPOL 1;

Markus_L811


How can I directly write a register value in my code?

For example the PWM_CMR_CPOL (0x1u << 9) change the register value 0 to 1.

Code: [Select]
// This doesn't work
#define PWM_CMR_CPOL 1;


That won't work. #define works like a placeholder everywhere the compilers find the term PWM_CMR_CPOL he would replace it with a 1.

Something like this should set the register Value to a 1
Code: [Select]

PWM->PWM_CMR = PWM_CMR_CPOL;


vorkiej

#2
Mar 25, 2013, 04:30 pm Last Edit: Mar 25, 2013, 04:33 pm by vorkiej Reason: 1
Thanks Markus_L811, that really helped me!

Code: [Select]

// solution of my problem was (don't forget the channel number!):
PWM->PWM_CH_NUM[6].PWM_CMR |= PWM_CMR_CPOL;
PWM->PWM_CH_NUM[6].PWM_CMR |= (1 << 9);                // or this

// simple test for printing the register values:
void test() {
   uint32_t registervalues;
   registervalues = PWM->PWM_CH_NUM[6].PWM_CMR;
   Serial.println(registervalues,BIN);                                  
   delay(1000);
}

// look in the header files for register names, in my case: component_pwm.h  and instance_pwm.h


Markus_L811

Good, but sorry really missed the channelname.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy