S-Function / ADS1115

2 Ansichten (letzte 30 Tage)
Denny Rohland
Denny Rohland am 25 Jan. 2023
Beantwortet: SANKALP DEV am 11 Okt. 2023
Hello Experts
I built an S-Function for the use of ADS1115 I2C modules.
Unfortunately I get an error at the end of the compiler run in Simulink which refers to the library used.
This in turn leads to the physical level of the I2C function on the Arduino.
Now the question is:
Do I have to integrate the entire physical connection and associated parameters so that I can read out the analog voltage on the I2C modules?
/*
Invalid use of operator.
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
#ifndef MATLAB_MEX_FILE
#include <Arduino.h>
#define ARDUINO 100
#include <Wire.h>
#include <Wire.cpp>
#include "utility/twi.h"
/*#include "api/HardwareI2C.h"*/
#include "ADS1115_WE.h"
/*#include "ADS1115_WE.cpp"*/
#define I2C_ADDRESS_1 0x48
#define I2C_ADDRESS_2 0x49
ADS1115_WE adc_1 = ADS1115_WE(I2C_ADDRESS_1);
ADS1115_WE adc_2 = ADS1115_WE(I2C_ADDRESS_2);
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output function
*
*/
extern "C" void i2C_ADS1115_Outputs_wrapper
( double A0_ADC1,
double A1_ADC1,
double A2_ADC1,
double A3_ADC1,
double A0_ADC2,
double A1_ADC2,
double A2_ADC2,
double A3_ADC2,
const real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
if(xD[0] == 1)
{
#ifndef MATLAB_MEX_FILE
A0_ADC1 = adc_1.getResult_V();
A1_ADC1 = adc_1.getResult_V();
A2_ADC1 = adc_1.getResult_V();
A3_ADC1 = adc_1.getResult_V();
A0_ADC2 = adc_1.getResult_V();
A1_ADC2 = adc_1.getResult_V();
A2_ADC2 = adc_1.getResult_V();
A3_ADC2 = adc_1.getResult_V();
#endif
}
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
extern "C" void i2C_ADS1115_Update_wrapper(real_T * A0_ADC1,
real_T *A1_ADC1,
real_T *A2_ADC1,
real_T *A3_ADC1,
real_T *A0_ADC2,
real_T *A1_ADC2,
real_T *A2_ADC2,
real_T *A3_ADC2,
real_T *xD)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
if(xD[0] != 1)
{
#ifndef MATLAB_MEX_FILE
adc_1.setMeasureMode(ADS1115_SINGLE);
adc_2.setMeasureMode(ADS1115_SINGLE);
adc_1.setCompareChannels(ADS1115_COMP_0_GND);
adc_2.setCompareChannels(ADS1115_COMP_0_GND);
adc_1.init();
adc_2.init();
#endif
xD[0] = 1; //done with initialization
}
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}
And the Simulink Error:
i2C_ADS1115_wrapper.o: In function `TwoWire::write(unsigned char)':
i2C_ADS1115_wrapper.cpp:(.text._ZN7TwoWire5writeEh+0x58): undefined reference to `twi_transmit'
i2C_ADS1115_wrapper.o: In function `TwoWire::write(unsigned char const*, unsigned int)':
i2C_ADS1115_wrapper.cpp:(.text._ZN7TwoWire5writeEPKhj+0x42): undefined reference to `twi_transmit'
i2C_ADS1115_wrapper.o: In function `i2C_ADS1115_Outputs_wrapper':
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Outputs_wrapper+0x26): undefined reference to `ADS1115_WE::getResult_V()'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Outputs_wrapper+0x2e): undefined reference to `ADS1115_WE::getResult_V()'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Outputs_wrapper+0x36): undefined reference to `ADS1115_WE::getResult_V()'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Outputs_wrapper+0x3e): undefined reference to `ADS1115_WE::getResult_V()'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Outputs_wrapper+0x46): undefined reference to `ADS1115_WE::getResult_V()'
i2C_ADS1115_wrapper.o:i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Outputs_wrapper+0x4e): more undefined references to `ADS1115_WE::getResult_V()' follow
i2C_ADS1115_wrapper.o: In function `i2C_ADS1115_Update_wrapper':
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Update_wrapper+0x2c): undefined reference to `ADS1115_WE::setMeasureMode(ADS1115_MEASURE_MODE)'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Update_wrapper+0x38): undefined reference to `ADS1115_WE::setMeasureMode(ADS1115_MEASURE_MODE)'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Update_wrapper+0x44): undefined reference to `ADS1115_WE::setCompareChannels(ADS1115_MUX)'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Update_wrapper+0x50): undefined reference to `ADS1115_WE::setCompareChannels(ADS1115_MUX)'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Update_wrapper+0x58): undefined reference to `ADS1115_WE::init()'
i2C_ADS1115_wrapper.cpp:(.text.i2C_ADS1115_Update_wrapper+0x60): undefined reference to `ADS1115_WE::init()'
collect2.exe: error: ld returned 1 exit status
gmake[1]: *** [../i2c_read.elf] Error 1

Antworten (1)

SANKALP DEV
SANKALP DEV am 11 Okt. 2023
Hi Denny,
I understand that you have encountered an error while using an S-Function for the ADS1115 I2C modules in Simulink.
The error message you have encountered suggests that there are unresolved references to functions and variables from the library you are utilizing. This typically occurs when the linker is unable to locate the necessary definitions for these functions and variables.
To resolve this issue, you can follow these steps:
  • Verify that the library files (ADS1115_WE.h and ADS1115_WE.cpp) are correctly included in your project. Ensure that these files are present in the appropriate location and properly referenced in your code. Double-check the file paths to ensure they are accurate.
  • Confirm the compatibility of the library with your Arduino and Simulink versions. It is important to check if the library supports the ADS1115 module and the required functions.
  • Make sure that the library files (ADS1115_WE.h and ADS1115_WE.cpp) are included in the build process. The linker error suggests that it cannot find the definitions for the functions and variables used from the library. Ensure that these files are correctly referenced in the build settings of your Simulink project.
By following these steps, you should be on the right track to resolve the error.
Best regards,
Sankalp

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by