i2c using lpc open

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by plantman on Tue Feb 11 02:19:27 MST 2014
I am trying to use a ds1338 rtc (ds1307 compatible) on i2c with an lpc812 max board using pins P0_10, P0_11(marked sda scl) I have tried with and without pullup resistors.

I have it working on a 3.3v arduino setup but when I try to use it with  lpc open i just get an error.

Could someone please tell me the correct lpcopen code I need to use to replicate the arduino code below.

any help much appreciated.

In arduino I use


  byte zero = 0x00;

  Wire.requestFrom(DS1307_ADDRESS, 1);

what I have tried to use with lpc open.

static void readDateI2CMaster(uint16_t AddressI2C, int *date)
uint8_t recvData[10], sendData[10];
I2C_PARAM_T param;
I2C_RESULT_T result;
ErrorCode_t error_code;
int sindex = 0, rindex = 0;

sendData[sindex++] = (uint8_t) AddressI2C  | 0x00;
sendData[sindex++] = (uint8_t) 0x00;

recvData[rindex++] = (uint8_t) AddressI2C  | 0x01;

param.num_bytes_send    = 2;
param.num_bytes_rec     = 1;
param.buffer_ptr_send   = &sendData[0];
param.buffer_ptr_rec    = &recvData[0];
param.stop_flag         = 1;
#if defined(INTERRUPTMODE)
param.func_pt           = cbI2CComplete;

/* Set timeout (much) greater than the transfer length */
LPC_I2CD_API->i2c_set_timeout(i2cHandleMaster, 100000);

/* Do master read transfer */
#if defined(INTERRUPTMODE)
intErrCode = -1;

/* Function is non-blocking, returned error should be LPC_OK, but isn't checked here */
error_code = LPC_I2CD_API->i2c_master_receive_intr(i2cHandleMaster, &param, &result);

/* Sleep until transfer is complete, but allow IRQ to wake system
   to handle I2C IRQ */
while (intErrCode == -1) {

/* Cast saved error code from callback */
error_code = (ErrorCode_t) intErrCode;

error_code = LPC_I2CD_API->i2c_master_receive_poll(i2cHandleMaster, &param, &result);

/* Completed without erors? */
if (error_code != LPC_OK) {
/* Likely cause is NAK */
DEBUGOUT("i2c_master_receive error code : %x\r\b", error_code);

*date = (int) recvData[1];