Header- / Source-file related question

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Header- / Source-file related question

2,972 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Mon Apr 09 15:42:14 MST 2012
Hi,

i got a question that may be little bit stupid but i dont find my fault.

The problem is this:
I want to create a source-file/header-file-combo, which will be included into main.c and provides functions and defines for an external chip, which is connected to the LPC via i2c.

So i included the i2c.h into mylib.c, aswell as mylib.h. mylib.h is included to main.c. To have access to the global variables, i2c.h is also included to main.c.

The problem is, defines from i2c.h cannot be used in mylib.c, even though they are correctly included and lying in the same folder! I dont unterstand this error!

Help! :(
0 Kudos
Reply
19 Replies

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 12 21:48:29 MST 2012
Hey Rob65..

I am sorry. I was nt knowing dis. Anyway I wil not do so again. Can u plz help me on ma topic.

Thanks.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Thu Apr 12 08:18:41 MST 2012

Quote: researchinnovation
[SIZE=4][B][COLOR=Blue]Hi...!!! [/COLOR][/B][/SIZE]



Why are you posting a non related question in 3 different topics ?
Please post you question only once and please open a new thread if you want to address a new question.

I think things like this have been asked before ...
Please search the forum to see if that results in an answer.

Rob
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by researchinnovation on Thu Apr 12 02:14:01 MST 2012
[SIZE=4][B][COLOR=Blue]Hi...!!!
I want to take/read file(.txt format doc format) continuously as an input for one of my application on I2C.
But when I use FILE *file and file =fopen("filename.txt","r"); it is   showing error and I tried few more things but it is showing error.
I have used #include "debug_printf.h" , #include "stdlib.h" and other required driver files, but still error is coming.

Please guide me on this or share any document available on c functions for LPCxpresso.

Thanks....:)[/COLOR][/B][/SIZE]
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Wed Apr 11 02:35:55 MST 2012
thank you for your help and encouragement.

It is some time ago since i used c and i didnt remember the simple thing, that the order of the includes does matter. Im very sorry to bother you with these puny problems.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Apr 11 02:16:51 MST 2012
Including driver_config.h *BEFORE* you include i2c.h works

Have you *ever* programmed in C before? Whatever, I suggest you go and take a C programming course before posting any more questions.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Wed Apr 11 02:12:45 MST 2012
in driver_config.h at line 32 i defined it:
#define CONFIG_ENABLE_DRIVER_I2C                        1

so, it must be fine, since i2c-functions from i2c.h/.c in main work as expected. as well als all other drivers.

EDIT:
including driver_config.h into test.c didnt help :(
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Apr 11 02:07:02 MST 2012
What abouit the
#if CONFIG_ENABLE_DRIVER_I2C==1
at the start of i2c.h?

You need to
#define CONFIG_ENABLE_DRIVE_I2C 1

either in you code, or in the compiler settings
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Wed Apr 11 02:02:24 MST 2012
ok, here you go.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Apr 11 01:43:15 MST 2012
As mentioned above :rolleyes:

Quote: Zero
#4 If you don't know why your settings don't work, export and post your project. Otherwise it's difficult to understand what you've done exactly.

0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Wed Apr 11 01:05:45 MST 2012
@arneb:
Hi, the define is definately set in the driver_config.h. Otherwise my i2c-interface wouldnt work (what it does).

@thefallguy:
Building file: ../driver_IRTe/test.c
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -D__USE_CMSIS -DDEBUG -D__CODE_RED -I../cmsis -I"C:\<<<<<path>>>>>\driver_IRTe" -I../config -I../driver -O0 -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -MMD -MP -MF"driver_IRTe/test.d" -MT"driver_IRTe/test.d" -o"driver_IRTe/test.o" "../driver_IRTe/test.c"
../driver_IRTe/test.c: In function 'blub':
../driver_IRTe/test.c:9:15: error: 'BUFSIZE' undeclared (first use in this function)
../driver_IRTe/test.c:9:15: note: each undeclared identifier is reported only once for each function it appears in
../driver_IRTe/test.c:10:1: warning: control reaches end of non-void function
make: *** [driver_IRTe/test.o] Error 1
here you go Its pretty much default lpcxpresso settings.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Wed Apr 11 01:00:07 MST 2012
Hi Caradhras,

please have a look at the first lines of your i2c.h file:
#if CONFIG_ENABLE_DRIVER_I2C==1
If this #define is not set, it will skip the whole i2c header file (including the #define BUFSIZE 64), resulting in an compile error.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Wed Apr 11 00:37:46 MST 2012
Please post the complete output from the console build log, so we can see all the options to the compiler and all messages.
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Tue Apr 10 15:49:36 MST 2012
*facepalm*

ok, back to the original problem:

i now add the line:
#include "i2c.h"
from the NXP examples driver section. In the mentioned header i find this define:
#define BUFSIZE            64

now i modifiy my test.c to this:
#include "test.h"
#include "stdint.h"
#include "i2c.h"

uint32_t blub( uint32_t blub )
{
    return blub*BUFSIZE;
}
Problem:
../driver_IRTe/test.c:9:14: error: 'BUFSIZE' undeclared (first use in this function)
../driver_IRTe/test.c:9:14: note: each undeclared identifier is reported only once for each function it appears in
../driver_IRTe/test.c:10:1: warning: control reaches end of non-void function
make: *** [driver_IRTe/test.o] Error 1
So where do i find my facepalm here? Thanks for your patience!
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Tue Apr 10 15:42:48 MST 2012
*facepalm*
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Apr 10 15:38:22 MST 2012
What is 'uin32_t ':confused:

Either you correct it to uin[SIZE=7][B][COLOR=Red]t[/COLOR][/B][/SIZE]32_t or you explain it to your compiler :rolleyes:
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Tue Apr 10 15:34:11 MST 2012
hmm i see, but this doesnt work either:

test.h
#ifndef __TEST_H
#define __TEST_H

#include "stdint.h"

uin32_t blub( uint32_t blub );

#endif
result:
driver_IRTe/test.h:6:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'blub'

../src/main.c:245:2: warning: implicit declaration of function 'blub'
make: *** [src/main.o] Error 1
:confused:
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Apr 10 15:30:17 MST 2012
As already explained above:

#1 Without 'Source Folder' your folder content will not be compiled, so please use 'Source Folder' :confused:

#2 Your compiler is explaining you what's wrong here:


Quote:

.../test.h:4:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'blub'

Do you understand that?

'[B][COLOR=Red]uin32_t[/COLOR][/B]' is unknown in test.h, so this an error and a complete different issue :eek:
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Caradhras on Tue Apr 10 15:02:04 MST 2012
hmm,

i did a test with your directions:

1. created folder "driver_IRTe" in the main project folder (i also tried with create source folder to get the little c, but result was the same.)
2. went to properties and added this to the list of included folders. it now says:
../cmsis
"${workspace_loc:/${ProjName}/driver_IRTe}"
../config
../driver
3.created test.c and test.h in driver_IRTe, Contents:
test.c
#include "test.h"
#include "stdint.h"

uin32_t blub( uint32_t blub )
{
    return blub;
}
test.h
#ifndef __TEST_H
#define __TEST_H

uin32_t blub( uint32_t blub );

#endif
4. i included test.h into main.c and put the function call:
i = blub((uint32_t) 5);
5. This is what the compiler says:
C:\Users\username\Documents\LPCXpresso_4.1.5_219\workspace_i2c<<<<<path>>>>>\driver_IRTe/test.h:4:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'blub'
../src/main.c: In function 'main':
../src/main.c:245:2: warning: implicit declaration of function 'blub'
make: *** [src/main.o] Error 1


Is the explanation sufficient?
0 Kudos
Reply

2,932 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Apr 09 18:44:17 MST 2012
#1 Create a new Source Folder with (Right-Click on Project) New->Source Folder and put your Source / Header files in there.

#2 Then add it's relative path with "../MyNewSourceFolderName" in (Right-Click on Project) Properties -> C/C++ Build -> Settings -> Tool Settings -> MCU C Compiler -> Includes

#3 A lot of samples (NXP_LPCXpresso11C24_2011-01-27.zip) show how this works. If your Project Explorer shows a Subdirectory icon with a little 'C' this is a Source Folder.

#4 If you don't know why your settings don't work, export and post your project. Otherwise it's difficult to understand what you've done exactly.
0 Kudos
Reply