ATSAM3X programming .... NOT DECLARED IN THIS SCOPE

Hi guys,
iam very new to programing and arduino. Until now i worked a little bit with the ATMega328. For a project I used the following sketch which worked fine so far.

#include <Stdio.h>
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

//! Macro that clears all Timer/Counter1 interrupt flags.
#define CLEAR_ALL_TIMER1_INT_FLAGS    (TIFR1 = TIFR1)


int pinFreq = 5;

void setup()
{

  pinMode(pinFreq, INPUT);


  Serial.begin(115200);        // connect to the serial port

  // hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCR1A=0;                   // reset timer/counter1 control register A
  TCCR1B=0;                   // reset timer/counter1 control register A
  TCNT1=0;                    // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin T1 ( arduino pin 5)
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCR1B ,CS10);         // External clock source on T1 pin. Clock on rising edge.
  sbi (TCCR1B ,CS11);
  sbi (TCCR1B ,CS12);

  // timer2 setup / is used for frequency measurement gatetime generation
  // timer 2 presaler set to 256 / timer 2 clock = 16Mhz / 256 = 62500 Hz
  cbi (TCCR2B ,CS20);
  sbi (TCCR2B ,CS21);
  sbi (TCCR2B ,CS22);
  
  

  //set timer2 to CTC Mode
  cbi (TCCR2A ,WGM20);
  sbi (TCCR2A ,WGM21);
  cbi (TCCR2B ,WGM22);
  OCR2A = 31;                  // CTC at top of OCR2A / timer2 interrupt when coun value reaches OCR2A value

  // interrupt control

  sbi (TIMSK2,OCIE2A);          // enable Timer2 Interrupt

}

long freq_in;

void loop()
{
 
}

// Timer2 Interrupt Service is invoked by hardware Timer2 every 2ms = 500 Hz
//  16Mhz / 256 / 125 / 500 Hz
// here the gatetime generation for freq. measurement takes place: 

ISR(TIMER2_COMPA_vect) {

  freq_in=TCNT1;
  TCNT1=0;
  TCNT2=0;
  
  Serial.write(highByte(freq_in));
  Serial.write(lowByte(freq_in));

}

I aimed to measure an altering frequency of an external frequency generator. To be able to measure higher frequencies than 16MHz i bought a Arduino Due with the ATSAM3X µc. A little bit naive i thought i could use the sketch from above also for the ATSAM3X. But the first try out ended with a lot of errors that all say … was not declared in this scope.
Therefore i searched for all the functions and commands and tried to translate them. For example:
The Control Register for ATmega: TCCR1A
The Control Register for ATSAM: TC_CCR1

Now i hoped that this would work. But again there appears the error : TC_CCR1 is not declared in this scope
Furtheron Iam still looking for Registers like TIFR, OCR2A … are this registers not longer avaible or are there other registers with the same function ? I looked up all the commands at the datasheet … but as you see they dont work at all :confused:

So please could anybody help me ?
Thank you in advance !!!

That code is completely non-portable. You'll need to dig into the data sheets for both the 328 and the Due, to see what the registers on the 328 are, and then find the corresponding register on the Due is, if there is even one.

Mentioning something about which version of the IDE you are using would be useful, as well as showing the modified code.

Iam using the beta 1.5.4 by arduino. Today I was looking the whole day for corresponding codes. As mentioned before if found a few. like the control register (TC_CCR x[x=0-2]) and the TC Interrupt Mask Register (TC_IMRx[x=0-2]) . But if i replace them in the sketch the error still appears, also for the new register names. By the way this is the reason why i don´t have a modified code until now :roll_eyes: . Do I need to initialize the new codes at the beginning ? ... Didn´t do this as the privios sketch didn´t do as well ? For my knwoledge i would just replace the register names ?! Sorry for maby curious questions ^^

regards kohlmeise

The DUE does not have any of the same registers or ports ect as the avrs (Uno ....) so of course they are not declared. And as the Sam chips are so very different from the avrs there is no way to do a simple conversion. You need to re-write the code completely

Mark

Thanks a lot guys !