Found my problem. The write function was using an uninitialized stack value, causing random values to be sent to the control registers of the BMS280.
Hey I am also facing the same issue,can you tell me where exactly in the write function