2

I'm having trouble passing a struct into a function and I am running into an error:

'PWM_PINS' undeclared (first use in this function)

I am typically able to do this in a C++ compiler without any trouble. I would appreciate some advice as to what I might be doing wrong here.

I have included the relevant parts from the header and c file below.

pwm.h file:

typedef struct PWM_tag{
    int PWM_1;
    int PWM_2;
    int PWM_3;
    int PWM_4;
    int PWM_5;
    int PWM_6;
} PWM;

void PWM_Set( uint32_t channelNum, uint32_t cycle, PWM PWN_PINS );

pwm.c file:

#include "pwm.h"
 void PWM_Set( uint32_t ChannelNum, uint32_t cycle, PWM PWN_PINS)
    {
        if ( ChannelNum == 1 )
        {
            LPC_PWM1->MR0 = cycle;
            LPC_PWM1->MR1 = PWM_PINS.PWM_1;
            LPC_PWM1->MR2 = PWM_PINS.PWM_2;
            LPC_PWM1->MR3 = PWN_PINS.PWM_3;
            LPC_PWM1->MR4 = PWM_PINS.PWM_4;
            LPC_PWM1->MR5 = PWM_PINS.PWM_5;
            LPC_PWM1->MR6 = PWM_PINS.PWM_6;

        }
        return;
    }

2 Answers 2

4

You declared a parameter called PWN_PINS (with an N), but you are referring to PWM_PINS (with an M).

Fixing this typo will address this particular error. There may be more errors, though - it's hard to tell, because the snippet does not show essential parts, such as the declaration of LPC_PWM1 variable.

2
  • Thank you! Wow... very embarrassing, but you probably saved me an hour more of banging my head against the table :)
    – stephf0716
    Nov 12, 2012 at 3:31
  • @stephf0716 That's OK, something like this has happened to me more times than I'm willing to admit :) Nov 12, 2012 at 3:35
2

Is there misspelling in the code?

The function parameter is PWN_PINS.But the code have 5 PWM_PINS, and one PWN_PINS.

I think what you should do is to change all PWN_PINS to PWM_PINS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.