Pages: [1]   Go Down
Author Topic: avr code in arduino  (Read 319 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is my sketch

Code:
void setup() {
  Ethernet.begin(mac,ip);
  server.begin();
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
init_CPU();
.........
}

in the header file i have
Code:
#ifndef TX_H_
#define TX_H_
.....

void init_CPU (void);

....


and in c file i have
Code:
void init_CPU (void)
{
// do something
}

while compiling i get that " init_CPU was not declared in this scope"
what am i doing wrong?
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is that all of your sketch ?  I think not.  Can you post all of it please ?

If it is all of your sketch should you not be #including the library ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

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

Can you post all of it please ?
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <TX.h>
#include<avr/io.h>
void setup() {
// initialize the ethernet device
  Ethernet.begin(mac,ip);
  // start listening for clients
  server.begin();
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
init_CPU();
  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

the full file is about 600 lines

i have imported the header file  TX.h  and c file  TX.c
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50861
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and in c file i have
C++ allows multiple functions (methods) to have the same name, if they have different argument types. The way that this is supported is through name mangling, where the real function name is based on the argument types.

C does not.

So, the C++ compiler performs name mangling. The C compiler does not. The linker is looking for the name mangled function, which it can't find, because the C compiler didn't mangle the name.

The easiest solution is to use .cpp as the file extension, so it is the C++ compiler that gets invoked, not the C compiler.

If you don't like that idea, hit google for help calling C functions from C++.
Logged

Pages: [1]   Go Up
Jump to: