Invalid conversion from 'int' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

Hello guys.
I'm here for asking some helps to solve my problem.
I'm trying to use "Arduino nano 33 BLE sense" board communicate with 3d hall sensor ( made in Infineon ) by using I2C. Thanks to the engineer, I just checked that it works well with my Arduino Uno board with the sensor. However, when I try to change compiling setting to "Arduino nano 33 BLE sense" It makes error line like this:

sketch\hall3d.cpp: In function 'void WriteMirrorToSensorReg()':
hall3d.cpp:351:57: error: invalid conversion from 'int' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
(void) I2CWrite ( TLI493D_A1, RSRV2_R, senReg[RSRV2_R]);
^
In file included from sketch\hall3d.cpp:2:0:
sketch\interface.h:8:9: note: initializing argument 2 of 'uint8_t I2CWrite(uint8_t, uint8_t*, uint8_t)'
uint8_t I2CWrite( uint8_t addr, uint8_t * wData, uint8_t wLength);
^~~~~~~~
exit status 1
invalid conversion from 'int' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

Can't understand why this error outbreaks not on "Arduino Uno" Settings.

It will be really thankful if you help me.

I just want to attach my zip file on this forum, but websites blocks me. :frowning:

Start here

Please follow the advice given in the link below when posting code . Use code tags when posting code here to make it easier to read and copy for examination

This is my code:

TLI 493D_SerialPrint_stucked


#include "hall3d.h"
#include "interface.h"
#include <Arduino.h>
#include <Wire.h>

void setup() {
  //-------------------------
  //  enable Serial
  //-------------------------
  Serial.begin(9600);
  while (!Serial);
  //-------------------------
  //  Init Sensor
  //  one bye read mode
  //  master contol mode
  //-------------------------
  initSensor( );
}

void loop() {
  
  sensorUpdata();
  Serial.println(getX());
  Serial.println((String)"Bx = " + getX());
  Serial.println((String)"By = " + getY());
  Serial.println((String)"Bz = " + getZ());
  Serial.println((String)"Temp = " + getTemp());
  Serial.print((String)"Angle = ");
  Serial.println(getAngle());
  delay(500);
} 

and here is .h and .cpp file i used

hall3d.h

#ifndef __HALL3D_H__
#define __HALL3D_H__
#include <Arduino.h>


#define SENSOR_IIC_ADDR   TLI493D_A0
    
//------------------------------------------------
// Main Function & Struct 
//--------------------------------------------------

typedef struct _sensorData {   
    int16_t BX;
    int16_t BY;
    int16_t BZ;
    int16_t TEMP;
} sensorData;


void initSensor ( void );
void sensorUpdata(void);
int16_t getX(void);
int16_t getY(void);
int16_t getZ(void);
int16_t getTemp(void);
float getAngle(void);


//------------------------------------------------
//TLI493D W2BW i2C slave device address(7bit format)
//--------------------------------------------------


#define TLI493D_A0  0x35 //7 bit address format
#define TLI493D_A1  0x22 //7 bit address format
#define TLI493D_A2  0x78 //7 bit address format
#define TLI493D_A3  0x44 //7 bit address format


//------------------------------------------------
//TLI493D W2BW Power On/Off Control pin number
//--------------------------------------------------

//
#define SensorPowerCtrlPin  5
#define INT_PIN        9

//------------------------------------------------
// Option. 몇번째 레지스터까지 읽을래?
// 6 ==> X, Y, Z, Temp           7 ==> X, Y, Z, Temp and Diag
//--------------------------------------------------

#define NumOfRdata   6 
#define numOfReg 23 //0x00~0x16

//------------------------------------------------
//TLI493D reg inital setting 
//------------------------------------------------

#define DT      0            //0 -> enable Temp(defualt), 1->  disable temp

#define AM      0            //0 -> measure Bx,y,z(Default)  , 1->  measure Bx,y only

#define TRIG    2            //0 -> no ADC trig @ one-byte read mode (default) 
                             //1 -> ADC trig before reading First MSB @ one-byte read mode 
                             //2 -> ADC trig after reading reg 0x05(temp+bz) @ one-byte read mode 

#define X2_sens    0
//#define X4_sens    0        //'00'-->[X2_sens:X4_sens]--> full range
                            //'10'-->[X2_sens:X4_sens]--> short range
                            //'11'-->[X2_sens:X4_sens]--> extra short range

#define TL_mag  1            // 0-> TC0 ( no temp compensation )
                             // 1-> TC2 ( temp compensation with TC1)
                             // 2-> TC3 ( temp compensation with TC2)
                             // 3-> TC4 ( temp compensation with TC3)


#define IICadr  0
                             // 0-> IIC addr 0x35 (equvalant  product A0 type) (default)
                             // 1-> IIC addr 0x22 (equvalant  product A1 type)
                             // 2-> IIC addr 0x78 (equvalant  product A2 type)
                             // 3-> IIC addr 0x44 (equvalant  product A3 type)
                          

#define PR  1                // 0-> 2byte read mode (default)-->  not allowed in this SW
                             // 1-> 1byte read mode 

#define CA_INT   1           // 0-> INT endable but no interrupt during I2C communication (CA active) 
                             // 1-> INT diable & Clock stetching enabled
                             // 2-> INT enable but there are possubilty inttrupt during i2c(CA not active )
                             // 3-> INT disble & Clock stetching disable (not recommended)


#define MODE   1             // 0-> LP mode         (defalut)
                             // 1-> Master mode 
                             // 2-> not allowed 
                             // 3-> fast mode 
                             
#define PRD    0            // 0->fupdate ≈ 770 Hz  (default)                          
                            // 1->fupdate ≈ 97 Hz
                            // 2->fupdate ≈ 24 Hz
                            // 3->fupdate ≈ 12 Hz
                            // 4->fupdate ≈ 6 Hz
                            // 5->fupdate ≈ 3 Hz
                            // 6->fupdate ≈ 0.4 Hz
                            // 7->fupdate ≈ 0.05 Hz



//----------------------------
// Read sensor data struct
//----------------------------


typedef struct _sensorConfigRegs {
  
    uint8_t  Dt;
    uint8_t  Am;     
    uint8_t  Trig; 
    uint8_t  x2_sens;
//    uint8_t  x4_sens;
    uint8_t  Tl_mag;   
    uint8_t  iiCadr;
    uint8_t  Pr;    
    uint8_t  Ca_int;    
    uint8_t  Mode;               
    uint8_t  Prd;  

    //============================
    uint8_t  WA;    //Read only
    uint8_t  WU;    
    uint8_t  TST;
    uint8_t  PH;    
    
    uint16_t XW;
    uint16_t YW;
    uint16_t ZW;
    
} sensorConfigRegs;



#endif 

hall3d.cpp

#include "hall3d.h"
#include "interface.h"
#include <Arduino.h>
//#include <Wire.h>

//---------------------------------------
//Internal function
//----------------------------------------
//extern sensorConfigRegs sensorConfig;
void  SimpleAssembleSensorData( sensorData * mag  , uint8_t * sDATA );
void EnableOneByteReadOnly (void);
void PowerOn();
void WriteMirrorToSensorReg (void);
void sensorMirrorRegInit (void);
uint8_t  CalParity( uint8_t * regData, uint8_t numByte);
void SensorRead(sensorData * mag, uint8_t numByte);

//====================
// Glrobal variable  
//=====================
sensorConfigRegs sensorConfig;
sensorData mag;
volatile uint16_t  sensorUpdated =0;
uint8_t senReg [numOfReg];
void magFieldReady_ISR (void);


void sensorMirrorRegInit (void){
      sensorConfig.Dt=DT;
      sensorConfig.Am= AM;     
      sensorConfig.Trig= TRIG; 
      sensorConfig.x2_sens= X2_sens;
//      sensorConfig.x4_sens= X4_sens;
      sensorConfig.Tl_mag= TL_mag;   
      sensorConfig.iiCadr= IICadr;
      sensorConfig.Pr= PR;    
      sensorConfig.Ca_int= CA_INT;    
      sensorConfig.Mode= MODE;               
      sensorConfig.Prd= PRD  ;
}




#define BX_R      0x00
#define BY_R      0x01
#define BZ_R      0x02

#define TEMP_R    0x03

#define BX2_R     0x04
#define TEMP2_R   0x05
#define DIAG_R    0x06      //Sensor diagnostic and status register
#define XL_R      0x07
#define YL_R      0x09
#define ZL_R      0x0B
#define XH_R      0x08
#define YH_R      0x0B
#define ZH_R      0x0C
#define WU_R      0x0D
#define TMODE_R   0x0E
#define TPHASE_R  0x0F
#define CONFIG_R  0x10      //Configuration register
#define MOD1_R    0x11      //Power mode, interrupt, address, parity
#define RSRV1_R   0x12      //reserved
#define MOD2_R    0x13      //Low Power Mode update rate
#define RSRV2_R   0x14      //reserved
#define RSRV3_R   0x15      //reserved
#define VER_R     0x16      //Version

//========================================
// define bit positon of sensor reg 
//========================================

#define DT_bs          7
#define AM_bs          6
#define TRIG_bs        4
#define X2_sens_bs     3
//#define X4_sens_bs     0
#define TL_mag_bs      1

#define IICadr_bs   5
#define PR_bs       4
#define CA_INT_bs   2
#define MODE_bs     0
#define PRD_bs      5


//
//void EnableOneByteReadOnly (void){
//    Wire.beginTransmission(SENSOR_IIC_ADDR);
//    Wire.write(0x11);             // Config, 0x10
//    Wire.write(0b10011000);       // MOD1 register,  master controlled mode, one byte read command, enabled interrupt, no collision avoidance, odd FP parity
//    Wire.endTransmission();
//}


void EnableOneByteReadOnly (void){

  //======================================
  // Set REG to Known status without Fuse parity error for basic interface
  // It is only for read interface
  // It make One byte read mode , MASTER,Disable interrupt, Enable Clock steching 
  // after this, you should reconfig sensorConfig res which will be applied to your application
  // FP should not be corrupted , no update on FP
  //=======================================
 
  //One byte, MASTER,Disable interrupt, Enable Clock steching ,PRD=0x00 with correct FP
   uint8_t MOD1_PRD[3];
    MOD1_PRD[0]=0x15;
    MOD1_PRD[1]=0x38;
    MOD1_PRD[2]=0x00;
  (void) i2cWriteArray ( SENSOR_IIC_ADDR, MOD1_R , MOD1_PRD,3 );
  
}



void  SimpleAssembleSensorData( sensorData * mag  , uint8_t * sDATA ){

  int16_t bx,by,bz,temp;
  uint8_t diag,ubyte, parity;
  sensorData HallData;
  mag->BX=(int8_t) *(sDATA+0);
  mag->BY=(int8_t) *(sDATA+1);
  mag->BZ=(int8_t) *(sDATA+2);
  mag->TEMP=(int8_t) *(sDATA+3);
  ubyte=*(sDATA+4);
  
  //assemble bx into int16
  mag->BX=(mag->BX)<<4;
  mag->BX=(mag->BX)|(ubyte>>4);

  //assemble by into int16
  mag->BY=(mag->BY)<<4;
  mag->BY=(mag->BY)|(0x0F&ubyte);

  //assemble bz into int16
  ubyte=*(sDATA+5);
  mag->BZ=(mag->BZ)<<4;
  mag->BZ=(mag->BZ)|(0x0F&ubyte);
  

  //assemble temp into int16
  mag->TEMP=(mag->TEMP)<<4;
  mag->TEMP=(mag->TEMP)|( 0x0C&(ubyte>>4) );
  
   //DIAG byte
  //mag->TEMP=*(sDATA+6);
}







//----------------------------------------------------
// if ODD parity --> return 1
//----------------------------------------------------
uint8_t  CalParity( uint8_t * regData, uint8_t numByte){

  uint8_t i,parity;

  parity=*(regData+0);
  for (i=1;i<numByte;i++)    
    parity^=*(regData+i);


    
  parity ^= parity >> 4;
  parity ^= parity >> 2;
  parity ^= parity >> 1;
  return (parity&0x01); 
  
}


void SensorRead(sensorData * mag,uint8_t numByte ){
    uint8_t reg[7];
    (void)I2cRead(SENSOR_IIC_ADDR, reg, numByte);
    (void)I2cRead(SENSOR_IIC_ADDR, reg, numByte);
    SimpleAssembleSensorData(  mag  , reg ); 
}


void sensorUpdata(void){  
  SensorRead(&mag,7);
}

int16_t getX(void){
 
  return mag.BX; 
}

int16_t getY(void){

  return mag.BY; 
}

int16_t getZ(void){

  return mag.BZ; 
}

int16_t getTemp(void){
  return mag.TEMP; 
}




float getAngle(void){
 
  float angle ; 
  angle = atan2(mag.BX, mag.BY)*180/PI;
  return angle ; 
}


void PowerOn(void){
    pinMode(SensorPowerCtrlPin,OUTPUT);
    digitalWrite(SensorPowerCtrlPin,HIGH);
    delay(100);
    digitalWrite(SensorPowerCtrlPin,LOW);
    delay(50);
}



uint8_t updateCP (void){
  uint8_t cpReg[10] ;   //0x07~0x10

  //copy 
  for (int16_t i =0 ; i< 10;i++){
    cpReg[i]=senReg[0x07+i];
  }

  cpReg[6]= cpReg[6]&(~0x80);  //bit[7] Clear   in 0x0D reg
  cpReg[7]= cpReg[7]&(~0xC0);  //bit[7:6] Clear in 0x0E reg
  cpReg[8]= cpReg[8]&(~0xC0);  //bit[7:6] Clear in 0x0F reg
  cpReg[9]= cpReg[9]&(~0x01);  //bit[1] Clear in 0x10 reg

  //return CalParity 1  if odd 
  if( CalParity( cpReg, 10) ) {
      return 0x00;
  } else{
      return 0x01;
  } 

}


uint8_t updateFP (void){
  uint8_t cpReg[2] ;   //0x07~0x10

  //copy 
  cpReg[0]=senReg[MOD1_R];
  cpReg[1]=senReg[MOD2_R];
  
  //bitclear 
  cpReg[0]= cpReg[0]&(~0x80);  //bit[7] Clear in 0x11 reg
  cpReg[1]= cpReg[1]&(~0x1F);  //bit[7:5] Clear in 0x13 reg
  
  // CalParity() return 1  if odd 
  if( CalParity( cpReg, 2) ) {
      return 0x00;
  } else{
      return 0x80;
  } 

}




void initSensor ( void ) {
  
  //---------------------------
  // Power on
  //--------------------------
//  PowerOn();

  //---------------------------
  // Init I2C
  //--------------------------  
   initI2C();
  
  //======================================
  // enable One byte read interface
  //=======================================
  EnableOneByteReadOnly();
  
  //======================================
  // update sensosrMirrorReg as default value 
  //=======================================
  sensorMirrorRegInit();
  
  //======================================
  // Write sensorMirrorReg to Sensor's real Register with correct parity bit
  //=======================================
  WriteMirrorToSensorReg();
    //======================================
  // sensor measurement done ISR attach
  //=======================================
  //pinMode(INT_PIN, INPUT);
  //attachInterrupt(digitalPinToInterrupt(INT_PIN),magFieldReady_ISR, FALLING);  
}







void WriteMirrorToSensorReg (void){

  //=================================================================
  //  Copy sensor Register to senReg for CP calculation & block write 
  //==================================================================
  (void) I2cRead(SENSOR_IIC_ADDR,senReg,numOfReg); 


  //=================================================================
  //update  Config & Mod1 & Mod2 & RSRV2 reg from sensorConfig value
  //=================================================================
 
  senReg[CONFIG_R]=((sensorConfig.Dt)<<DT_bs)|((sensorConfig.Am)<<AM_bs)|((sensorConfig.Trig)<<TRIG_bs)|((sensorConfig.x2_sens)<<X2_sens_bs)|((sensorConfig.Tl_mag)<<TL_mag_bs);
  senReg[MOD1_R]=((sensorConfig.iiCadr)<<IICadr_bs)|((sensorConfig.Pr)<<PR_bs)|((sensorConfig.Ca_int)<<CA_INT_bs)|((sensorConfig.Mode)<<MODE_bs);
  senReg[MOD2_R]=(sensorConfig.Prd)<<PRD_bs;
  //senReg[RSRV2_R]=(sensorConfig.x4_sens)<<X4_sens_bs;


  //===================================================
  //  CP,FP update 
  //===================================================
   senReg[CONFIG_R]= (senReg[CONFIG_R]&(~0x01))|updateCP();
   senReg[MOD1_R]= (senReg[MOD1_R]&(~0x80))|updateFP();


  //========================================================================
  // Write to sensor  form config(0x10) upto Mod2(0x13) , RSRV2_R register 
  //========================================================================
  (void) i2cWriteArray ( TLI493D_A0, CONFIG_R, & (senReg[CONFIG_R]),4);
  (void) I2CWrite ( TLI493D_A0, RSRV2_R, senReg[RSRV2_R]);


}

//
//void magFieldReady_ISR (void){
//
// 
//  sensorUpdated=1;
//  if (sensorConfig.Mode!=1){  // if opreation mode is not MASTER mode)
//
//      SensorRead(&mag,NumOfRdata); 
//
//  }
// 
//
//}

interface.h

#ifndef __INTERFACE_H__
#define __INTERFACE_H__
#include <Arduino.h>

#define II2C_BaudRate     400000

void initI2C (void);
uint8_t I2CWrite( uint8_t addr, uint8_t * wData, uint8_t wLength);
uint8_t I2cRead ( uint8_t i2cAddr, uint8_t * data, uint8_t len);
uint8_t i2cWriteArray ( uint8_t i2cAddr, uint8_t regAddr, uint8_t * data,uint8_t len );

#endif 

interface.cpp

#include <Wire.h>
#include <Arduino.h>
#include "interface.h"
 



void initI2C(void) {
  Wire.begin();
  Wire.setClock(II2C_BaudRate);

}


uint8_t I2CWrite( uint8_t addr, uint8_t * wData, uint8_t wLength){
  int i;
  Wire.beginTransmission(addr);
  for (i=0;i++;i< wLength){
    Wire.write(*(wData+i)); 
  }
  Wire.endTransmission();  
  
}


uint8_t I2cRead ( uint8_t i2cAddr, uint8_t * data, uint8_t len){

  uint8_t receivedBytes,i;
  receivedBytes= Wire.requestFrom(i2cAddr, len);    // request 2 bytes from slave device #112

  if (receivedBytes == len)
  {
    for (i = 0; i < len; i++)
    {
      *(data+i) = Wire.read();
    }
  }
  return receivedBytes;
} 


uint8_t i2cWriteArray ( uint8_t i2cAddr, uint8_t regAddr, uint8_t * data,uint8_t len ){
  uint8_t i;
  //return 
  //0:success
  //1:data too long to fit in transmit buffer
  //2:received NACK on transmit of address
  //3:received NACK on transmit of data
  //4:other error
  Wire.beginTransmission(i2cAddr);    // send sensor start bit + sensor addr                             
  Wire.write(0x20|regAddr);           // ADC trigger after Write frame is finished 
  for (i=0;i<len;i++) {
    Wire.write( *(data+i) ); 
  }
  return (Wire.endTransmission());    // stop transmitting
  
}

And Error message is just like this when I compile this file for board setting of "Arduino nano 33 BLE Sense"

sketch\hall3d.cpp: In function 'void WriteMirrorToSensorReg()':
hall3d.cpp:345:57: error: invalid conversion from 'int' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
   (void) I2CWrite ( TLI493D_A0, RSRV2_R, senReg[RSRV2_R]);
                                                         ^
In file included from sketch\hall3d.cpp:2:0:
sketch\interface.h:8:9: note:   initializing argument 2 of 'uint8_t I2CWrite(uint8_t, uint8_t*, uint8_t)'
 uint8_t I2CWrite( uint8_t addr, uint8_t * wData, uint8_t wLength);
         ^~~~~~~~
exit status 1
invalid conversion from 'int' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

Why try to write obscure code?

Wire.write(wData[i]);
*(data+i) = Wire.read();

Ditto.

This function wants address, pointer to array and length of data

You send ???

also what is with casting every function call to void?

You are passing a fixed number to the function instead of a pointer for the 2nd argument.

#define RSRV2_R   0x14      //reserved

  (void) I2CWrite ( TLI493D_A0, RSRV2_R, senReg[RSRV2_R]);

The code generates a warning on an UNO because the compiler options are set to be more permissive of errors than on the Nano 33 BLE, the code is still incorrect on an UNO.

/home/test/Arduino/TLI_493D_SerialPrint_stucked/hall3d.cpp: In function 'void WriteMirrorToSensorReg()':
/home/test/Arduino/TLI_493D_SerialPrint_stucked/hall3d.cpp:345:57: warning: invalid conversion from 'int' to 'uint8_t* {aka unsigned char*}' [-fpermissive]
   (void) I2CWrite ( TLI493D_A0, RSRV2_R, senReg[RSRV2_R]);
                                                         ^
In file included from /home/jdbarney/Arduino/TLI_493D_SerialPrint_stucked/hall3d.cpp:2:0:
/home/test/Arduino/TLI_493D_SerialPrint_stucked/interface.h:8:9: note:   initializing argument 2 of 'uint8_t I2CWrite(uint8_t, uint8_t*, uint8_t)'
 uint8_t I2CWrite( uint8_t addr, uint8_t * wData, uint8_t wLength);
         ^~~~~~~~
/home/test/Arduino/TLI_493D_SerialPrint_stucked/interface.cpp: In function 'uint8_t I2CWrite(uint8_t, uint8_t*, uint8_t)':
/home/test/Arduino/TLI_493D_SerialPrint_stucked/interface.cpp:18:17: warning: for increment expression has no effect [-Wunused-value]
   for (i=0;i++;i< wLength){
                ~^~~~~~~~~
/home/test/Arduino/TLI_493D_SerialPrint_stucked/interface.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

In addition to the error you are asking about, the for statement is written incorrectly in the I2CWrite function.

1 Like

Yowzer!

1 Like

Priceless!

1 Like