Hi,
I'm using a KL03 as an I2C master and it is sending the following bytes to a slave with address 0x43:
(0x43 << 1) | 0
0x01
(0x43 << 1) | 1
and then the expectation is to read a byte back from the slave.
However, the problem I'm seeing is that the second time I write the slave address, it shows up as 0 (irrespective of what I actually write) and then the data read is always 0xFF. See attached screenshot.
Here's some snippets of the code I'm using:
// init function
/* Enable clock for SPI0 module */
SIM_SCGC4 |= SIM_SCGC4_I2C0_MASK;
PORT_PCR_REG( PORTA_BASE_PTR, 3 ) = PORT_PCR_MUX(2); // SCL
PORT_PCR_REG( PORTA_BASE_PTR, 4 ) = PORT_PCR_MUX(2); // SDA
I2C0_C1 = 0x0;
I2C0_C2 = 0x0;
/* No slave address, so this is master */
I2C0_A1 = 0x0;
I2C0_C1 |= I2C_C1_IICIE_MASK;
I2C0_S1 = I2C_S1_IICIF_MASK | I2C_S1_ARBL_MASK;
/* Initialize and set I2C baudrate to default value */
i2c_set_baudrate( i2cInfo.baudRate );
/* Enable I2C0 Interrupts */
enable_int_vector( INT_I2C0, INT_MAX_PRIORITY_DEFAULT );
I2C0_C1 |= I2C_C1_IICEN_MASK;
// I trigger the I2C transfer to the slave by writing
/* Send start signal */
I2C0_C1 |= I2C_C1_MST_MASK;
/* Set to TX mode */
I2C0_C1 |= I2C_C1_TX_MASK;
/* Write byte */
I2C0_D = (slaveAddr << 1) | 0;
// And then the rest of the processing is done in the IRQ handler which basically does the following
// first IRQ
I2C0_S1 |= I2C_S1_IICIF_MASK;
I2C0_D = 0x1;
// second IRQ
I2C0_S1 |= I2C_S1_IICIF_MASK;
I2C0_C1 |= I2C_C1_RSTA_MASK;
I2C0_D = (slaveAddr << 1) | 1;
// third IRQ
I2C0_S1 |= I2C_S1_IICIF_MASK;
I2C0_C1 &= ~I2C_C1_TX_MASK;
I2C0_C1 |= I2C_C1_TXAK_MASK;
readData = I2C0_D;
// fourth IRQ
I2C0_S1 |= I2C_S1_IICIF_MASK;
I2C0_C1 |= I2C_C1_TXAK_MASK;
I2C0_C1 |= I2C_C1_TX_MASK;
I2C0_C1 &= ~I2C_C1_MST_MASK;
Does anyone have any idea of what might be causing this? Appreciate the help.
