I2C Slave transmiting not wanted value (LPC802)

cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Slave transmiting not wanted value (LPC802)

Jump to solution
244 Views
asier
Contributor III

Hi,

I have configure my I2C slave as follow:

bool ini_i2c(void)
{
  i2c_slave_config_t slaveConfig;
  status_t reVal = kStatus_Fail;

  /* Set up i2c slave */
  I2C_SlaveGetDefaultConfig(&slaveConfig);

  /* Change the slave address */
  slaveConfig.address0.address = I2C_MASTER_SLAVE_ADDR_7BIT;

  /* Initialize the I2C slave peripheral */
  I2C_SlaveInit(EXAMPLE_I2C_SLAVE, &slaveConfig, I2C_SLAVE_CLOCK_FREQUENCY);

  memset(g_slave_buff, 0, sizeof(g_slave_buff));

  /* Create the I2C handle for the non-blocking transfer */
  I2C_SlaveTransferCreateHandle(I2C0, &g_s_handle, i2c_slave_callback, NULL);

  NVIC_SetPriority(I2C0_IRQn, 2);

  /* Start accepting I2C transfers on the I2C slave peripheral */
  reVal = I2C_SlaveTransferNonBlocking(I2C0, &g_s_handle,
  kI2C_SlaveAddressMatchEvent | kI2C_SlaveCompletionEvent);
  if (reVal != kStatus_Success)
  {
    return -1;
  }
  return 0;
}

Then, in the callback function I do following:

const uint8_t dat = 0;

uint8_t g_slave_buff[8];

static void i2c_slave_callback(I2C_Type *base, volatile i2c_slave_transfer_t *xfer, void *userData)
{
switch (xfer->event)
{
/* Address match event */
case kI2C_SlaveAddressMatchEvent: // Received the slave address after a start or repeated start.
  xfer->rxData = NULL;
  xfer->rxSize = 0;
  xfer->txData = NULL;
  xfer->txSize = 0;
break;

/* Transmit request */
case kI2C_SlaveTransmitEvent: // Callback is requested to provide data to transmit (slave-transmitter role).
switch (g_slave_buff[0])
{
  case 0xA0:
    if (dat != 0) Toogle_TEST();
    xfer->txData = &dat;
    xfer->txSize = 1;
}
break;

/* Setup the slave receive buffer */
case kI2C_SlaveReceiveEvent: // Callback is requested to provide a buffer in which to place received data (slave-receiver role).
  xfer->rxData = g_slave_buff;
  xfer->rxSize = I2C_DATA_LENGTH;
break;

}

}

It works as expected, but sometimes I can see that 0x00 data is not transmitted and instead of it I see 0x01 data is sent. The issue happens randomly. What could be the reason ? 

I attach a graph showing undesired 0x01 sending.

Thanks,

Asier.

0 Kudos
1 Solution
234 Views
asier
Contributor III

It seems that It was not a software problem. Changing values of resistor pull-ups from 4K7 to 1K in SCL and SDA lines issue is solved.

Thanks you,

Asier.

View solution in original post

0 Kudos
2 Replies
240 Views
asier
Contributor III

Sorry, but in the graph TEST signal (trace in red) is toogling because "const uint8_t dat = 0;"  definition produces "if (dat != 0) Toogle_TEST();" to be true.

I've checked that declaring "int8_t dat = 0;" TEST signal is not toogling when 0x01 is transmitting. So "dat" variable has correct 0 value.

0 Kudos
235 Views
asier
Contributor III

It seems that It was not a software problem. Changing values of resistor pull-ups from 4K7 to 1K in SCL and SDA lines issue is solved.

Thanks you,

Asier.

0 Kudos