cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 5, 3 & 1

Switten
New Contributor II

Hello this is my first post and first PSOC project that I am doing. What I am trying to do is to read the data from the mpu6050 gyroscoop with I2C.

But i am getting a error when i try to build the code. The error i am getting is Build error: undefined reference to 'gyro_WriteReg'. But when I click on go to declaration I go to the .h file I have, so I think the problem is not with the connection with the .c & .h file but somewhere else.

 

Can someone explain why i get this error?

Aantekening 2021-11-14 114416.png

See atached file for project

0 Likes
1 Solution
MotooTanaka
Esteemed Contributor

Hi,

Thank you for uploading the project.

Now I could reproduce the problem.

And what I noticed was that since you have an I2C component "I2C" in your schematic,

there were file named "I2C.h" and "I2C.c" in the Generated_Source / PSoC5 / I2C

So I renamed your i2c.c and i2c.h to i2c_gyro.c and i2c_gyro.h.

And now your project could be compiled.

moto

View solution in original post

4 Replies
MotooTanaka
Esteemed Contributor

Hi,

 

Your attached project contained only the project file,

it would be easier for others to see what is your problem

if you can archive the whole project and post.

 

I have just re-read the I2C.h automatically generated

========================

/* I2C Master functions prototypes */
#if (I2C_MODE_MASTER_ENABLED)
/* Read and Clear status functions */
uint8 I2C_MasterStatus(void) ;
uint8 I2C_MasterClearStatus(void) ;

/* Interrupt based operation functions */
uint8 I2C_MasterWriteBuf(uint8 slaveAddress, uint8 * wrData, uint8 cnt, uint8 mode) \
;
uint8 I2C_MasterReadBuf(uint8 slaveAddress, uint8 * rdData, uint8 cnt, uint8 mode) \
;
uint8 I2C_MasterGetReadBufSize(void) ;
uint8 I2C_MasterGetWriteBufSize(void) ;
void I2C_MasterClearReadBuf(void) ;
void I2C_MasterClearWriteBuf(void) ;

/* Manual operation functions */
uint8 I2C_MasterSendStart(uint8 slaveAddress, uint8 R_nW) \
;
uint8 I2C_MasterSendRestart(uint8 slaveAddress, uint8 R_nW) \
;
uint8 I2C_MasterSendStop(void) ;
uint8 I2C_MasterWriteByte(uint8 theByte) ;
uint8 I2C_MasterReadByte(uint8 acknNak) ;

#endif /* (I2C_MODE_MASTER_ENABLED) */

========================

And I could not find I2C_ReadReg() and/or I2C_WriteReg(),

So probably, the user (programmer) need to write WriteReg() function.

Your error seems that the gyro_WriteReg()  is declared in the header file,

but the linker could not find the real implementation of that function.

 

FYI, I have written and posted some sample code for PSoC 5LP including a simple usage of I2C.

https://community.infineon.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-059-v...

https://community.infineon.com/t5/Code-Examples/MCU-Tester-a-Swiss-Army-Knife-for-PSoC-CY8CKIT-050-v...

In those project, I implemented i2c_read_reg() and i2c_write_reg() functions in i2c_utils.h/i2c_utils.c,
hopefully these can be some hint for you.

 

moto

0 Likes
Switten
New Contributor II

as asked i have uploaded the project and now normally it is the whole project. The files where

gyro writeReg is mentioned is a seperate .c & .h file that i wrote. (i2c.c & i2c.h)

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

Thank you for uploading the project.

Now I could reproduce the problem.

And what I noticed was that since you have an I2C component "I2C" in your schematic,

there were file named "I2C.h" and "I2C.c" in the Generated_Source / PSoC5 / I2C

So I renamed your i2c.c and i2c.h to i2c_gyro.c and i2c_gyro.h.

And now your project could be compiled.

moto

View solution in original post

Switten
New Contributor II

thank you, the errors are now gone.