I have a code written in C language. I want to write a code that can get temperature and pressure data with the BMP280 sensor into this code. However, I saw that the person who originally wrote the code made his own definitions using twi.c instead of the Wire.h library.
For this reason, I tried to use the BMP280 using datasheet, but I could not succeed. Is there anyone who can help?
look up details of the I2C interface on the datasheet of the microcontroller you are using
it will give details of the registers, bit settings, etc so you can write your own code to drive the interface directly
alternativily you could use almost any GPIO pin by bit bashing
I tried very hard but could not. Because the ready code was written in C language, creating its own i2c.h library and using twi.h made it quite difficult.
when you say you could not adapt it? what is your target processor?
if I run the code from post #6 on a UNO I get
Pressure : 1020.65 hPa
Temperature in Celsius : 23.36 C
Temperature in Fahrenheit : 74.04 F
Pressure : 1020.70 hPa
Temperature in Celsius : 23.39 C
Temperature in Fahrenheit : 74.10 F
Pressure : 1020.68 hPa
Temperature in Celsius : 23.39 C
Temperature in Fahrenheit : 74.10 F
When you use the Arduino IDE to make a sketch, then you already use a lot C++. You can use "C" or "C++", both are okay, you don't have to choose. You can even combine it with assembly.
Almost every library uses a class.
Koepel:
When you use the Arduino IDE to make a sketch, then you already use a lot C++. You can use "C" or "C++", both are okay, you don't have to choose. You can even combine it with assembly.
Almost every library uses a class.
The "Serial" functions use a class, which is C++, just like the Wire library.
Why don't you want to use C++ ?
If you are not using the Arduino environment, is your question about programming a microcontroller without Arduino ?
Using a Arduino board with I2C without the Wire library is almost impossible. There is no reliable alternative for the Wire library.
I haven't fully tested this yet but this should cover the lowest level I2C read and writes for an Arduino using Atmega328P. It's not complete since I haven't implemented some error handling required for I2C
@ahmetkcavusoglu, you still have not told us why you want a Wire library with the C language.
The only thing that we can do now is guessing what the problem could be.
Please tell us what the problem is:
Do you think that once you choose the 'C' language that you no longer can use 'C++' ?
Does your code use the I2C bus ? and is it hard to convert it for the Wire library ? Please show us your code and we can help.
Does your code not go along with the Arduino setup() and loop() and attachInterrupt() ? Then there are probably easy ways to transform the code.
Is your project not Arduino code, but you still want to use the Arduino Wire library, and your compiler is not setup properly for C++ ? Tell us which compiler you use. There is no Wire library in 'C', because there is no need for it.
I wrote before that you don't have to choose.
You can combine 'C' and 'C++' and assembly in any way you want. The Arduino IDE and the compiler and linker all support that, in every combination.