4 Replies Latest reply on Jul 9, 2020 10:42 AM by FlHe_4723206

    Set register prior to I2C_MasterWriteBuf

    FlHe_4723206

      uint8 writeRegister8(uint8 i2c_address, uint8 reg, uint8 data){

              if(!I2C_MasterSendStart(i2c_address,0)){

                  I2C_MasterWriteByte(reg);

                  I2C_MasterWriteByte(data);

                  return I2C_MasterSendStop();

              }else{

                  I2C_MasterSendStop();

                  return 1;

              }

          }else{

              return 99u; //placeholder

          }

      }

       

      with the loop in my main code being:

       

       

          for(uint8 i=0; i<BUF_LENGTH; i++){

              status = writeRegister8(i2c_address, PWM_REGISTER+i,gamma32[brightness]);

          }

       

      I want to replace the loop+function call with I2C_MasterWriteBuf function. However, I2C_MasterWriteBuf does not have a register field. I have tried all sorts of combinations of writing register address first as a byte, restarting the bus, stopping and starting again, writing the buffer directly after setting the register address... Nothing works in terms of that the slave device never gets the right values.

       

      Basic question is: How do I use

      I2C_MasterWriteBuf

      in an intended way when I need to set a register to write to first?