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