Undefined Reference for read&write functions in I2C library

Hi,

I am using the nRF52840-dongle. I tried to create and application with the i2c library for bme280 sensor. When I run the following I get the error in linking step that there is undefined reference for i2c_read_reg and i2c_write_reg.

make BOARD=nrf52840dongle -C examples/myapplication

RIOT/examples/myapplication/bin/nrf52840dongle/bmx280/bmx280.o: in function _read_reg': /RIOT/drivers/bmx280/bmx280.c:102: undefined reference to i2c_read_reg’

I have checked weather i2c.h is included in the application via bmx280.h—>it is included following the makefiles i2c defination. Also the sources should be compilled for i2c.c via some of the

"make" -C /RIOT/drivers/periph_common

What exactly causes such error?

Seems that I could be missing something in Makefile, here is the Makefile of my application…

> # Set the name of your application:
> APPLICATION = foobar
> 
> # If no BOARD is found in the environment, use this default:
> CPU += nrf52
> BOARD += nrf52840dongle
> DRIVER ?= bme280_i2c
> USEMODULE += fmt
> USEMODULE += $(DRIVER)
> USEMODULE += xtimer
> 
> USEMODULE += bme280_i2c
> USEMODULE += bmp280_i2c
> 
> FEATURES_PROVIDED += periph_i2c
> FEATURES_PROVIDED += periph_uart
> USEMODULE += dht
> 
> CFLAGS += -DBMX280_PARAM_I2C_DEV=I2C_DEV\(0\)
> CFLAGS += -DBMX280_PARAM_I2C_ADDR=0x76
> # This has to be the absolute path to the RIOT base directory:
> RIOTBASE ?= $(CURDIR)/../../
> QUIET ?= 1
> include $(RIOTBASE)/Makefile.include
> CPU += nrf52

Drop that, it’s set implicitly by selecting the right board.

That line should be BOARD ?= nrf52840dongle. If set, it is the default for BOARD, no need to specify again on the command line.

> DRIVER ?= bme280_i2c
> USEMODULE += $(DRIVER)
> 
> USEMODULE += bme280_i2c
> USEMODULE += bmp280_i2c

Only the line USEMODULE += bme280_i2c should suffice.

> FEATURES_PROVIDED += periph_i2c
> FEATURES_PROVIDED += periph_uart

FEATURES_PROVIDED is something that’s used by a board configuration. If you intended to use i2c or uart, use FEATURES_REQUIRED instead. but both periph_uart and periph_i2c should be pulled automatically by the dependency resolution.

Hi,

I did some changes as you have mentioned in the Makefile but the undefined reference in .o files continues to pop-up. This is both for /test/driver_bmx280 and also for my application in examples/myapplication. One thing I am not sure is that it always fails after the line.

"make" -C /home/ujjval/RIOT/sys/xtimer

Hi @ujurmsde you might as well want to take a look at Build System Basics for more information on what all these variables mean. Cheers,

Francisco

@ujurmsde can you try adding USEMODULE += periph_i2c?

@Kaspar I have tried your suggestion but the problem is still there.

BTW The problem is always with I2C. I tried some examples from /test/Driver_xxx/ First the error is about feature requirements

There are unsatisfied feature requirements: periph_i2c

And after I add features the above mentined main error remains.! :pensive:

BTW, I have another RIOT in a totally different folder where I am able to use the I2C!!,

I will try my custom example there.

i2c pinout was added to nrf52840dongle after 2021.04, so maybe your (not working) RIOT tree is a bit too old?

1 Like

Exactly, my RIOT download was older than 04/2021. Thanks for the clerification.

I just verified it in a file /board/nrf52840dongle/include/perif_conf.h and I did not found the i2c configurations!!