Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Comparing the function output ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

How can compare the result of the furnction output ?

I have on main.c :
Code:
result = VS1053_Init();
		if (result == 0)
		{	
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 1 );
			HAL_Delay(100);
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 0 );
		}

and :

vs.c :
Code:
unsigned char VS1053B_Init()
{
.
.
.
return 0;
}

Thanks
 

I'm not sure what your problem is. The variable 'result' takes the value that was set in the 'return' instruction in the function. Just make sure the same type is used, the function returns an 'unsigned char' so you must make sure you declare "unsigned char result;" somewhere before the function is called.

You might be able to save a variable by using "if(VS1053_Init() == 0)".

Brian.
 

I want to see if the function is returning 1 or 0

If it's 0, I can continue...

When I put :
if (VS1053_Init() == 0)

I got :

Error: L6218E: Undefined symbol VS1053_Init (referred from main.o).

Any clues ? thanks

I'm not sure what your problem is. The variable 'result' takes the value that was set in the 'return' instruction in the function. Just make sure the same type is used, the function returns an 'unsigned char' so you must make sure you declare "unsigned char result;" somewhere before the function is called.

You might be able to save a variable by using "if(VS1053_Init() == 0)".

Brian.
 

You have to define function prototype before the main function

Code:
[B]unsigned char VS1053B_Init[(void)[/B];

int main()
{
//user code
}

unsigned char VS1053B_Init()
{
//your function
}

Note: If your function is in another source file (.c) then define the prototype in respective header file and include this header file in your main source file.
 
Last edited:

Still I can not do this :

Code:
		if ((VS1053_Init()) == 0)
		{	
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 1 );
			HAL_Delay(100);
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 0 );
		}

How can I do that ?
You have to define function prototype before the main function

Code:
[B]unsigned char VS1053B_Init[(void)[/B];

int main()
{
//user code
}

unsigned char VS1053B_Init()
{
//your function
}

Note: If your function is in another source file (.c) then define the prototype in respective header file and include this header file in your main source file.
 

Hope you have added your source file (vc.c) in your project. Compile after adding the source c file in your project.
 

it has been added but I got :
Code:
 Error: L6218E: Undefined symbol VS1053_Init (referred from main.o).
Not enough information to list image symbols.

Hope you have added your source file (vc.c) in your project. Compile after adding the source c file in your project.
 

Typo in there...
The prototype should read
Code:
unsigned char VS1053B_Init(void);
there is an extra '[' in the code that shouldn't be there.
Just add the line near the start of your program OUTSIDE any functions. Make sure you add the ';' at the end of the line.

If you are referring to it from another .c file, add the prototype to the file that contains the function code and add
Code:
extern unsigned char VS1053B_Init();
at the top of the other file using the function. It tells the linker program to use the function already there so it doesn't look for a second copy and fail to find it.

Brian.
 

this is what I have :
on vs.c
Code:
unsigned char VS1053B_Init()
{
...
}

on vs.h
Code:
unsigned char VS1053B_Init(void);

and on main.c :
Code:
if ((VS1053_Init()) == 0)
		{	
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 1 );
			HAL_Delay(100);
			HAL_GPIO_WritePin(GPIOE, GPIO_PIN_6 , 0 );
		}

What do I miss here ?
Thanks

Typo in there...
The prototype should read
Code:
unsigned char VS1053B_Init(void);
there is an extra '[' in the code that shouldn't be there.
Just add the line near the start of your program OUTSIDE any functions. Make sure you add the ';' at the end of the line.

If you are referring to it from another .c file, add the prototype to the file that contains the function code and add
Code:
extern unsigned char VS1053B_Init();
at the top of the other file using the function. It tells the linker program to use the function already there so it doesn't look for a second copy and fail to find it.

Brian.
 

1. The function is written in the file vs.c
2. vs.h contains the function prototype - so you must have "#include vs.h" at the top of vs.c, possibly in main .c as well.
3. The file using the function, main.c must be told the function is in another file so at the top add: "extern unsigned char VS1053B_Init();"

In 2. you may need to specify a full path to the file, it depends on your operating system and where the file is located.
In C, each source (.c) file is compiled separately, they have no knowledge of what is in any other files. this means that if you call a function that is in another file, it won't recognize it and you get an error. Adding 'extern' (short for 'external') tells the compiler not to show an error and to leave a place holder for the function address. During the linking process, the linker program finds the real address of the function and fills the place holder with it.

Brian.
 

1. Yes it is written in vs.c
2. Yes I have included vs.h at the top of vs.c...
3. Yes I have told main.c ...

I still got
Code:
 Error: L6218E: Undefined symbol VS1053_Init (referred from main.o).
Not enough information to list image symbols.

Any clues ??
thanks a lot
1. The function is written in the file vs.c
2. vs.h contains the function prototype - so you must have "#include vs.h" at the top of vs.c, possibly in main .c as well.
3. The file using the function, main.c must be told the function is in another file so at the top add: "extern unsigned char VS1053B_Init();"

In 2. you may need to specify a full path to the file, it depends on your operating system and where the file is located.
In C, each source (.c) file is compiled separately, they have no knowledge of what is in any other files. this means that if you call a function that is in another file, it won't recognize it and you get an error. Adding 'extern' (short for 'external') tells the compiler not to show an error and to leave a place holder for the function address. During the linking process, the linker program finds the real address of the function and fills the place holder with it.

Brian.

- - - Updated - - -

Ok, it does the job, it's a typo
I had written :

Code:
if (([B]VS1053_Init()[/B]) == 0)

suppose to be :
Code:
if (([B]VS1053B_Init()[/B]) == 0)

Thanks a lot guys...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top