Hello
I'm working through the Development Academy's Lesson 6 on I2C (https://academy.nordicsemi.com/topic/i2c-driver/).
I've created a project based on this lesson as a first step (using 'nRF Connect for VS Code' - v 2.2.0). The code is as follows:
"main.c"
#include <zephyr/kernel.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/sys/printk.h>
#define I2C0_NODE DT_NODELABEL(mysensor)
static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE);
void main(void)
{
if (!device_is_ready(dev_i2c.bus))
{
printk("I2C bus %s is NOT ready!\n\r",dev_i2c.bus->name);
return;
}
else
{
printk("I2C bus %s is READY!\n\r",dev_i2c.bus->name);
}
while (1)
{
}
}
The Overlay is as follows:
&i2c0 {
mysensor: mysensor@10{
compatible = "i2c-device";
reg = < 0x10 >;
label = "MYSENSOR";
};
};
The "prj.conf" is:
CONFIG_I2C=y
I am sure I've followed all that is suggested in the lesson, but when I build the project I come across the following error message 'chain' that originates with static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE); :
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:83:41: error: '__device_dts_ord_134' undeclared here (not in a function); did you mean '__device_dts_ord_13'?
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
72 | #define __DEBRACKET(...) __VA_ARGS__
| ^~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
| ^~~~~~~~~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\drivers\i2c.h:122:17: note: in expansion of macro 'COND_CODE_1'
122 | COND_CODE_1(DT_ON_BUS(node_id, i3c), \
| ^~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\toolchain\common.h:133:23: note: in expansion of macro '_DO_CONCAT'
133 | #define _CONCAT(x, y) _DO_CONCAT(x, y)
| ^~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:83:33: note: in expansion of macro '_CONCAT'
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:209:37: note: in expansion of macro 'DEVICE_NAME_GET'
209 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:226:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
226 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\drivers\i2c.h:107:16: note: in expansion of macro 'DEVICE_DT_GET'
107 | .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
| ^~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\drivers\i2c.h:124:30: note: in expansion of macro 'I2C_DT_SPEC_GET_ON_I2C'
124 | (I2C_DT_SPEC_GET_ON_I2C(node_id))) \
| ^~~~~~~~~~~~~~~~~~~~~~
c:\Workspace\nrf\5340\exI2C\002_I2C\src\main.c:35:43: note: in expansion of macro 'I2C_DT_SPEC_GET'
35 | static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE);
| ^~~~~~~~~~~~~~~
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_internal.h:72:26: note: in definition of macro '__DEBRACKET'
72 | #define __DEBRACKET(...) __VA_ARGS__
| ^~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_internal.h:64:9: note: in expansion of macro '__GET_ARG2_DEBRACKET'
64 | __GET_ARG2_DEBRACKET(one_or_two_args _if_code, _else_code)
| ^~~~~~~~~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_internal.h:59:9: note: in expansion of macro '__COND_CODE'
59 | __COND_CODE(_XXXX##_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\sys\util_macro.h:157:9: note: in expansion of macro 'Z_COND_CODE_1'
157 | Z_COND_CODE_1(_flag, _if_1_code, _else_code)
| ^~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\drivers\i2c.h:122:17: note: in expansion of macro 'COND_CODE_1'
122 | COND_CODE_1(DT_ON_BUS(node_id, i3c), \
| ^~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\toolchain\common.h:133:23: note: in expansion of macro '_DO_CONCAT'
133 | #define _CONCAT(x, y) _DO_CONCAT(x, y)
| ^~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:83:33: note: in expansion of macro '_CONCAT'
83 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
| ^~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:209:37: note: in expansion of macro 'DEVICE_NAME_GET'
209 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
| ^~~~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\device.h:226:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
226 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
| ^~~~~~~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\drivers\i2c.h:107:16: note: in expansion of macro 'DEVICE_DT_GET'
107 | .bus = DEVICE_DT_GET(DT_BUS(node_id)), \
| ^~~~~~~~~~~~~
C:\ncs\v2.2.0\zephyr\include\zephyr\drivers\i2c.h:124:30: note: in expansion of macro 'I2C_DT_SPEC_GET_ON_I2C'
124 | (I2C_DT_SPEC_GET_ON_I2C(node_id))) \
| ^~~~~~~~~~~~~~~~~~~~~~
c:\Workspace\nrf\5340\exI2C\002_I2C\src\main.c:35:43: note: in expansion of macro 'I2C_DT_SPEC_GET'
35 | static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE);
| ^~~~~~~~~~~~~~~
Can anyone suggest where I'm going wrong in my code, please?
Thanks
RoW