I2C set register with negative number

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by renan on Mon Mar 10 20:26:49 MST 2014

I'm trying to use the i2c library from lpcopen to communicate with a adxl345 accelerometer.
I'm just trying to set a register with for example: -25.

I'm using, for example this function:

void adxl345_write_reg (uint8_t reg, uint8_t data)
I2C_XFER_T xfer;
uint8_t TXBuffer[2];
uint8_t RXBuffer;

TXBuffer[0] = reg;
TXBuffer[1] = data;

xfer.slaveAddr = 0x53;
xfer.txBuff = TXBuffer;
xfer.txSz = 2;
xfer.rxBuff = &RXBuffer;
xfer.rxSz = 0;

Chip_I2C_MasterTransfer(I2C0, &xfer);

This is the declaration of the function in the last line:
int Chip_I2C_MasterTransfer(I2C_ID_T id, I2C_XFER_T *xfer)

And this is  I2C_XFER_T:
typedef struct {
uint8_t slaveAddr;/**< 7-bit I2C Slave address */
const uint8_t *txBuff;/**< Pointer to array of bytes to be transmitted */
int     txSz;/**< Number of bytes in transmit array,
   if 0 only receive transfer will be carried on */
uint8_t *rxBuff;/**< Pointer memory where bytes received from I2C be stored */
int     rxSz;/**< Number of bytes to received,
   if 0 only transmission we be carried on */
I2C_STATUS_T status;/**< Status of the current I2C transfer */

The problem is that my data is a negative number and the buffers are unsigned short (uint8_t).

How can I solve this problem?