Hi everyone ! I am trying to access to I2C bus of STM32 nucleo board , where I have wired a AS7265x spectrometer sensor. I have found on github,com (see here - https://github.com/jdesbonnet/as7265x/tree/master/src ) an interesting C program that does this task . So I have run it in a RIOT OS folder in order to adapt to RIOT but I found this error. ioctl(I2C_RDWR) in i2c_read: Bad file descriptor I supppose that the File descriptor of the slave device is not right. Can you help me to correct this error ? Thank you very much indeed. Bye
Sounds like you have build the application for the
native board. There is no
ioctl() in RIOT, but there is a native I2C driver for RIOT on Linux, so you can simulate your application on Linux using real I2C hardware.
BOARD=nucleo-… (with the proper name of your board) in your
make commands to build and flash the STM32 board.
By native I2C driver for RIOT on Linuxx do you mean this in the following github rep ?
No I mean the driver for the
native board that allows to run RIOT as a Linux process for simulation.
But turns out I2C has not been implemented here, only SPI and UART.
Where are you trying to call
ioctl() and for which board do you build?
sorry perhaps I have been not clear in my question. since I want to make portable into RIOT OS (my board is nucleo-f401re board) the program written for Linux in the repository HERE I have arranged a single main.c with the main routines in RIOT OS application folder and created a Makefile . I have left intact the header file AS7265x.h but I had some problems with the I2c.c and I2c.h version files provided in this repository since they use ioctl to write into the registers and also use different names for routines writing/reading from register and also for the use of file descriptor of the device. what should I do for i2c.c and I2c.h ? should I adapt the original ones or should I use the ones provided in Riot os ?
As far the use of IOCTL can I use it in Riot OS ?
This driver is using the Linux I2C API with a custom wrapper.
You’ll have to convert the driver to use the RIOT I2C API instead - e.g. by replacing
Maybe you are right. Anyway I think that something in the makefile include or Riot os setup os not correct. i would try to make some modifications before. Can You suggest me how to add the includes /usr/include/linux so that it can find these header files ? It is a try for now.
I think you got a bit confused. RIOT has nothing to do with Linux, it’s am operating system on it’s own. It can run as a Linux process for simulation purpose, but usually it will run on a microcontroller like your STM32 independent of any PC - including Linux headers won’t help you here.
OK. I agree. Now I will try to replace
i2c_write_reg() . OK .
What do you think if I use this code for i2c_write_reg and i2c_read_reg ?