#define STEP_PORT PORTD throws "expression cannot be used as a function" error

I am exploring Port Manipulation to control steppers and detect endstop pin changes. On the latest iteration of the code I have ran into this error:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

[...deleted a few empty lines for brevity...]

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\fedus\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\fedus\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\fedus\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10813 -build-path C:\Users\fedus\AppData\Local\Temp\arduino_build_47159 -warnings=none -build-cache C:\Users\fedus\AppData\Local\Temp\arduino_cache_976803 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -verbose C:\Users\fedus\Documents\Arduino\Wire_Winder\Wire_Winder.ino

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -hardware C:\Users\fedus\AppData\Local\Arduino15\packages -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -tools C:\Users\fedus\AppData\Local\Arduino15\packages -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\fedus\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10813 -build-path C:\Users\fedus\AppData\Local\Temp\arduino_build_47159 -warnings=none -build-cache C:\Users\fedus\AppData\Local\Temp\arduino_cache_976803 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avrdude.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avr-gcc.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -verbose C:\Users\fedus\Documents\Arduino\Wire_Winder\Wire_Winder.ino

Using board 'uno' from platform in folder: C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

Using core 'arduino' from platform in folder: C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3

Detecting libraries used...

"C:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\fedus\\AppData\\Local\\Temp\\arduino_build_47159\\sketch\\Wire_Winder.ino.cpp" -o nul -DARDUINO_LIB_DISCOVERY_PHASE

Using cached library dependencies for file: C:\Users\fedus\AppData\Local\Temp\arduino_build_47159\sketch\Limits.c

Using cached library dependencies for file: C:\Users\fedus\AppData\Local\Temp\arduino_build_47159\sketch\Motors.c

Generating function prototypes...

"C:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\fedus\\AppData\\Local\\Temp\\arduino_build_47159\\sketch\\Wire_Winder.ino.cpp" -o "C:\\Users\\fedus\\AppData\\Local\\Temp\\arduino_build_47159\\preproc\\ctags_target_for_gcc_minus_e.cpp" -DARDUINO_LIB_DISCOVERY_PHASE

"C:\\Program Files (x86)\\Arduino\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\fedus\\AppData\\Local\\Temp\\arduino_build_47159\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

Using previously compiled file: C:\Users\fedus\AppData\Local\Temp\arduino_build_47159\sketch\Limits.c.o

Using previously compiled file: C:\Users\fedus\AppData\Local\Temp\arduino_build_47159\sketch\Motors.c.o

"C:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\fedus\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\standard" "C:\\Users\\fedus\\AppData\\Local\\Temp\\arduino_build_47159\\sketch\\Wire_Winder.ino.cpp" -o "C:\\Users\\fedus\\AppData\\Local\\Temp\\arduino_build_47159\\sketch\\Wire_Winder.ino.cpp.o"

In file included from c:\users\fedus\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\io.h:99:0,

                 from c:\users\fedus\appdata\local\arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\pgmspace.h:90,

                 from C:\Users\fedus\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino/Arduino.h:28,

                 from C:\Users\fedus\AppData\Local\Temp\arduino_build_47159\sketch\Wire_Winder.ino.cpp:1:

C:\Users\fedus\Documents\Arduino\Wire_Winder\Wire_Winder.ino: In function 'void stepMotorX()':

Wire_Winder:14:19: error: expression cannot be used as a function

 #define STEP_PORT PORTD

                   ^

C:\Users\fedus\Documents\Arduino\Wire_Winder\Wire_Winder.ino:91:3: note: in expansion of macro 'STEP_PORT'

   STEP_PORT = STEP_PORT^(1<<X_STEP_BIT);

   ^~~~~~~~~

exit status 1

expression cannot be used as a function



The error "exit status 1 ... expression cannot be used as a function" highlights line 14 "#define STEP_PORT PORTD". Is this a consequence of using Arduino source libraries as GRBL doesn't seem to? If so, is there a work around? Am I just wrong completely?

#include <avr/interrupt.h>

////DDRD
//#define RX_BIT     0
//#define TX_BIT     1
//
////DDRB
//#define Spindle_EN_BIT  4
//#define Spindle_DIR_BIT 5


//Define step pulse output pins
#define STEP_DDR DDRD
#define STEP_PORT PORTD
#define X_STEP_BIT 2  //Uno Digital Pin 2
#define Y_STEP_BIT 3  //Uno Digital Pin 3
#define Z_STEP_BIT 4  //Uno Digital Pin 4
#define STEP_MASK   ((1<<X_STEP_BIT) | (1<<Y_STEP_BIT) |(1<<Z_STEP_BIT))

//Define step direction output pins
#define DIR_DDR     DDRD
#define DIR_PORT    PORTD
#define X_DIR_BIT  5  //Uno Digital Pin 5
#define Y_DIR_BIT  6  //Uno Digital Pin 6
#define Z_DIR_BIT  7  //Uno Digital Pin 7
#define DIR_MASK    ((1<<X_DIR_BIT) | (1<<Y_DIR_BIT) |(1<<Z_DIR_BIT))

//Define stepper driver enable/disable output pin
#define STEPPERS_DISABLE_DDR  DDRB
#define STEPPERS_DISABLE_PORT  PORTB
#define STEPPERS_DISABLE_BIT  0  //Uno Digital Pin 8
#define STEPPERS_DISABLE_MASK (1<<STEPPERS_DISABLE_BIT)

//Define limit switch output pins
#define LIMIT_DDR       DDRB
#define LIMIT_PORT      PORTB
#define X_LIMIT_BIT     1
#define Y_LIMIT_BIT     2
#define Z_LIMIT_BIT     3
#define LIMIT_MASK  ((1<<X_LIMIT_BIT) | (1<<Y_LIMIT_BIT) |(1<<Z_LIMIT_BIT))


void setup() {

    cli();                //Turn off Interrupts
    PCICR |=  0b00000001;   //PORTB Pin Change Interrupt Enabled
    PCMSK0 |= 0b0000010;  //Pin d9 has a Pin Change Interrupt attached
    sei();                // Turn on Interrupts

  Serial.begin(9600);
  steppers_init();
  limits_init();
}

void loop() {
//stepMotorX();
}

void steppers_init()
{
  Serial.println("*******************");
  //Configure step and direction interface pins
  STEPPERS_DISABLE_DDR |= STEP_MASK;
  Serial.print(" STEP_MASK : ");
  Serial.println(STEP_MASK, BIN);
  DIR_DDR |= DIR_MASK;
  Serial.print(" DIR_MASK : ");
  Serial.println(DIR_MASK, BIN);
  STEPPERS_DISABLE_DDR |= STEPPERS_DISABLE_MASK;
  Serial.print(" STEPPERS_DISABLE_MASK : ");
  Serial.println(STEPPERS_DISABLE_MASK, BIN);
  DDRD |= (STEP_MASK | DIR_MASK);  
  DDRB |= STEPPERS_DISABLE_MASK;
  Serial.print(" DDRD : ");
  Serial.println(DDRD, BIN);
}

void limits_init()
{
  Serial.println("*******************");
  //Configure limit interface pins
  LIMIT_DDR &= ~(LIMIT_MASK);
  Serial.print(" LIMIT_MASK : ");
  Serial.println(DDRB, BIN);
}

void stepMotorX()
{
  STEPPERS_DISABLE_PORT |= STEPPERS_DISABLE_MASK
//  PORTB |= 
  STEP_PORT = STEP_PORT^(1<<X_STEP_BIT);
  delay(50);
}


//X Limit interrupt
ISR(PCINT0_vect)
{
  //I know I shouldn't use this inside an ISR
  Serial.println("button clicked");  
}

I am making an electromagnet winder. I am using the CNC Shield 3.xx and using GRBL as an example to guide me.

Thank you for your time.

Here is the Schematic.

Being a new user, I can only post 2 links per post.

The error may well be before line #14. Please post the complete sketch

You're missing a semicolon in stepMotorX. If you use tools -> autoformat it would be immediately visible (if you know what to look for). Based on the indentations, it's wrong

void stepMotorX()
{
  STEPPERS_DISABLE_PORT |= STEPPERS_DISABLE_MASK
                           //  PORTB |=
                           STEP_PORT = STEP_PORT ^ (1 << X_STEP_BIT);
  delay(50);
}

Add a semicolon and the problem is gone.

Or after it :rofl:

1 Like

This is truth. Thank you.

This is the full sketch so far. You can trust there will be more errors before and after line #14 in the future! :rofl:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.