static int32_t drvI2c_sendBytes(i2cHandle_type *handler, uint8_t *data, uint32_t len) { /* * Fill FIFO with data. This example will send a MAX of 8 bytes since it * doesn't handle the case where FIFO is full */ while(0U != DL_I2C_fillControllerTXFIFO(handler->i2cBase, data, (uint16_t)len)) ; /* Wait for I2C to be Idle */ while (!( DL_I2C_getControllerStatus(handler->i2cBase) & DL_I2C_CONTROLLER_STATUS_IDLE)) ; /* Send the packet to the controller. * This function will send Start + Stop automatically. */ DL_I2C_startControllerTransfer(handler->i2cBase, handler->dev_addr, DL_I2C_CONTROLLER_DIRECTION_TX, (uint16_t)len); dPrintf("\r\n1. MSR 0x%X", handler->i2cBase->MASTER.MSR); /* Poll until the Controller writes all bytes */ while (DL_I2C_getControllerStatus(handler->i2cBase) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS) ; dPrintf("\r\n2. MSR 0x%X", handler->i2cBase->MASTER.MSR); /* Trap if there was an error */ if (DL_I2C_getControllerStatus(handler->i2cBase) & DL_I2C_CONTROLLER_STATUS_ERROR) { dPrintf("\r\nError - MSR 0x%X", handler->i2cBase->MASTER.MSR); if((DL_I2C_CONTROLLER_SCL_LOW == DL_I2C_getSDAStatus(i2cHandler.i2cBase)) || (DL_I2C_CONTROLLER_SCL_LOW == DL_I2C_getSCLStatus(i2cHandler.i2cBase))) { dPrintf("\tBus error: SDA or SCL low!"); //__BKPT(0); return -1; } else { ; } } /* Wait for I2C to be Idle */ while (!( DL_I2C_getControllerStatus(handler->i2cBase) & DL_I2C_CONTROLLER_STATUS_IDLE)) ; return 0; }