Go Down

Topic: compile error - with attachPCINT (Read 679 times) previous topic - next topic

mstadtler

Been chasing this one for awhile can one of you guys take a look - please > :o

I had to strip out main to get the file size down - I just included the header and the ISR routines


"here is the error "C:\Users\121776\AppData\Local\Temp\arduino_build_662642\sketch\Robotorl_12_8.ino.cpp.o"
Robotorl_12_8:86: error: expected constructor, destructor, or type conversion before '(' token

  attachPCINT(digitalPinToPCINT(busWrtADC), ISR_adc, RISING);

             ^

Robotorl_12_8:87: error: expected constructor, destructor, or type conversion before '(' token

  attachPCINT(digitalPinToPCINT(busWrtDAC), ISR_dac, RISING);

and here is the code

Code: [Select]



/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>

/*End of auto generated code by Atmel studio */

/*
 Name:    12_8
 Created: 4/20/2017 1:25:51 PM
 Author:  121776

 code to be used with KB debug code


 ******const int InBufFull = 4; changed from 2 in this version
 ========================================================
          ADCMD BASE+2
DLY | INHIBIT|  0 |0  |CH3  |CH2  |CH1  |CH0|
                         ADC CH NO.
==========================================================
        STATUS  BASE+5
===========================================================
CH3|CH2|CH1|CONV |AUTO INC|IBF|2'S COMP|OBF
========= =================================================
IBF = 0    means ready for DAC data                    
IBF = 1    means ready for DAC data In process

OBF= 1 means  adc conv. complete
OBF= 0 means adc conv.  NOT complete
*/
  
#include <AltSoftSerial.h>                                    //remove
#include <SPI.h>
#include <AH_MCP320x.h>
#include "PinChangeInterrupt.h"

//Beginning of Auto generated function prototypes by Atmel Studio
void config_DAC();
byte micro_rd_data_reg(byte reg);
void micro_wrt_data_reg(byte reg, byte wrt_value);
void wrt_dac(byte dac_ch, byte dac_hi, byte dac_lo);
unsigned int rd_adc(byte ch);
void ISR_adc(void );
void ISR_dac(void );
//End of Auto generated function prototypes by Atmel Studio


#define busWrtADC A5               //pin 28
#define busWrtDAC A4              //pin 27
# define ADC0_SELECT 2           //select for MCP3208  ch0-7                        // commented out for debug - required in final version
 // AH_MCP320x ADC_0(ADC0_SELECT);
# define ADC1_SELECT 1                // pin 16 select for MCP3208  ch8-15    
//  AH_MCP320x ADC_1(ADC1_SELECT);
  AltSoftSerial altSerial;                                           //REMOVE
  const int  DAC_SEL = 8;               // pin 14
  const int  DAC_SEL_bit = 0;             // pin 14 when used as set and clr
  const int IN = B00000000;
  const int  OUT = B11111111;
  const int PortC_Config = B001111;         //pins 27,28 input, 26,25,24,23 output
  const int DACLO_REG = 0;
  const int DACHI_REG = 1;
  const int DAC_REF_INT = 1;
  const int DESEL = 7;
  const int mwr_ADC_LO_REG = 4;           //4 because of hardware decode
  const int mwr_ADC_HI_REG = 3;             //3 because of hardware decode
  const int ADC_CMD_REG = 2;
  const int STATUS_REG = 5;
  const int  PORT_SEL_DISABLE = 7;
  const int STATUS_LED = 3;
  const unsigned int UPPER_ADC_SCALE = 3200;     // value can be adjusted
  const byte IBF = 2;     //IBF
  const byte OBF = 0; //OBF

  //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; global;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  //************************* volatile dec *******************************************
  volatile byte  vg_stat_reg_val = 0;
  volatile byte v_adc_flag = false;
  volatile byte v_dac_flag = false;
  volatile byte v_adc_ch = 255;
  volatile byte  v_dac_hi_reg =255;
  volatile byte  v_dac_lo_reg = 255;
  
 [color=red]attachPCINT(digitalPinToPCINT(busWrtADC), ISR_adc, RISING);
  [color=red][/color]attachPCINT(digitalPinToPCINT(busWrtDAC), ISR_dac, RISING);[/color][/color]

  
 
  // ******************************* SETUP RUN ONCE****************************
  void setup() {
  //  Serial.begin(9600);
  //  Serial.println("AltSoftSerial Test Begin");
    altSerial.begin(9600);
    UCSR0B = 0;                           //disable uart pin 2,3 -cannot us Port D unless this is run
    //DDRB = 101111;
    altSerial.begin(9600);                                                                   //remove
    pinMode(DAC_SEL, OUTPUT);                 // pin 14
    pinMode(ADC0_SELECT, OUTPUT);               // pin 15
    pinMode(ADC1_SELECT, OUTPUT);               // pin 16
    digitalWrite(DAC_SEL, HIGH);                  //init to inactive state

    pinMode(busWrtADC, INPUT_PULLUP);             //INTERRUPT  PIN ADC COMMAND
    pinMode(busWrtDAC, INPUT_PULLUP);             //INTERRUPT  PIN DAC COMMAND

    DDRC = PortC_Config;                      //enable input on pin 24, 25

    int junk = micro_rd_data_reg(DACLO_REG);          // CLEAR DAC IS FF
    junk = micro_rd_data_reg(ADC_CMD_REG);          // CLEAR DC IS FF
    
    /********** DEBUG *********/
        
    init_board();
    
  }
  //^^^^^^^^^^^^^^^^^^^^^^^^^^^ main loop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
  void loop() {


  
  void ISR_adc(void) {
    v_adc_ch = 0;                 //clear old data -
    
    DDRD = OUT;             //set port D 1 to 8 as output
    bitClear(vg_stat_reg_val,OBF);
    PORTD =  vg_stat_reg_val ;  // output  data -OBF CLEARED
    PORTC = STATUS_REG;         //SELECT PORT - LOW
      delayMicroseconds(2);
    PORTC = PORT_SEL_DISABLE;         //de SELECT PORT - HIGH
      delayMicroseconds(2);
    DDRD = IN;              //set port D 1 to 8 as input
      delayMicroseconds(2);          
    PORTC = ADC_CMD_REG;        //select ADC_CMD reg
      delayMicroseconds(2);
    v_adc_ch = (PIND & 0x0f) ;      //read port c
      delayMicroseconds(2);
    PORTC = PORT_SEL_DISABLE;     //de SELECT PORT - HIGH */
    v_adc_flag = true;          
    //valid write from PC to addr 122 or 182h starts the a/d
    // process by setting v_adc_flag to true
  }

  // when remote computer writes to BASE+ 0 this routine will  grab the dac low reg and dac high reg info
  //info and set the v_dac_flag to true, DAC HI BYTE must be written by host before Lo byte since low byte triggers int

  void ISR_dac(void) {
    v_dac_lo_reg = 0;
    DDRD = IN;                //set port D 1 to 8 as input
    delayMicroseconds(2);
    PORTC = DACLO_REG;              //SELECT PORT - LOW
    delayMicroseconds(2);
    v_dac_lo_reg = PIND;              // input data
    delayMicroseconds(2);
    PORTC = PORT_SEL_DISABLE;         //de SELECT PORT - HIGH
    delayMicroseconds(2);
    PORTC = DACHI_REG;
    delayMicroseconds(2);
    v_dac_hi_reg = PIND;
    PORTC = PORT_SEL_DISABLE;         //de SELECT PORT - HIGH
    v_dac_flag = true;
  }

  
/*more complex but faster code*/
  /*byte config[] = { DAC_SETUP, FILLER_BYTE, FILLER_BYTE, DAC_REF_INT }; int

  bitClear( PORTB,DAC_SEL_bit);
  for (int i = 0; i < 4; i++){
  SPI.transfer(config[i]);
  delayMicroseconds(10);
  }
  bitSet(PORTB,DAC_SEL_bit );
  }
  */



             ^

el_supremo

Code: [Select]
void loop() {



  void ISR_adc(void) {

Either you're missing an end brace }, or you're trying to define the ISR_adc function inside the loop() function.
Neither of those is a good idea.

Pete
Don't send me technical questions via Private Message.

mstadtler


Go Up