Pages: [1]   Go Down
Author Topic: Write register values in code  (Read 860 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// This doesn't work
#define PWM_CMR_CPOL 1;
Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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:
PWM->PWM_CMR = PWM_CMR_CPOL;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Markus_L811, that really helped me!

Code:
// 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
« Last Edit: March 25, 2013, 10:33:25 am by vorkiej » Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good, but sorry really missed the channelname.
Logged

Pages: [1]   Go Up
Jump to: