Hello,
I tested an LPCXpresso55S36 board (running LPC5536 MCU) and I can see the same behavior.
Below find the example code which is based on the i2c driver's interrupt transfer example (from SDK_2.x_LPC5536). I had to move I2C from Flexcomm2 to Flexcomm7 as the development board has the pullups connected to Flexcomm7 pins. Use the Pins Tool to register pins #37 (SDA) and #65 (SCL). Also I had to add some code to avoid infinite loops on error and instead print out the status.
Rant: I don't know why NXP provides these odd examples which do not match the development board they provide.
#include <stdio.h>
#include <string.h>
#include "pin_mux.h"
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_i2c.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define EXAMPLE_I2C_MASTER_BASE (I2C7_BASE)
#define I2C_MASTER_CLOCK_FREQUENCY (12000000)
#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)
#define I2C_MASTER_SLAVE_ADDR_7BIT (0x7EU)
#define I2C_BAUDRATE (100000) /* 100K */
#define I2C_DATA_LENGTH (33) /* MAX is 256 */
/*******************************************************************************
* Prototypes
******************************************************************************/
/*******************************************************************************
* Variables
******************************************************************************/
uint8_t g_master_txBuff[I2C_DATA_LENGTH];
uint8_t g_master_rxBuff[I2C_DATA_LENGTH];
i2c_master_handle_t g_m_handle;
volatile bool g_MasterCompletionFlag = false;
volatile status_t transfer_status = 99;
/*******************************************************************************
* Code
******************************************************************************/
static void i2c_master_callback(I2C_Type *base, i2c_master_handle_t *handle, status_t status, void *userData)
{
/* Signal transfer success when received success status. */
transfer_status = status;
g_MasterCompletionFlag = true;
}
/*!
* @brief Main function
*/
int main(void)
{
i2c_master_transfer_t masterXfer = {0};
status_t reVal = kStatus_Fail;
/* attach 12 MHz clock to FLEXCOMM0 (debug console) */
CLOCK_SetClkDiv(kCLOCK_DivFlexcom0Clk, 0u, false);
CLOCK_SetClkDiv(kCLOCK_DivFlexcom0Clk, 1u, true);
CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
/* attach 12 MHz clock to FLEXCOMM2 (I2C master) */
CLOCK_SetClkDiv(kCLOCK_DivFlexcom7Clk, 0u, false);
CLOCK_SetClkDiv(kCLOCK_DivFlexcom7Clk, 1u, true);
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM7);
/* reset FLEXCOMM for I2C */
RESET_PeripheralReset(kFC7_RST_SHIFT_RSTn);
BOARD_InitPins();
BOARD_BootClockPLL150M();
BOARD_InitDebugConsole();
PRINTF("\r\nI2C board2board interrupt example -- Master transfer.\r\n");
i2c_master_config_t masterConfig;
I2C_MasterGetDefaultConfig(&masterConfig);
/* Change the default baudrate configuration */
masterConfig.baudRate_Bps = I2C_BAUDRATE;
/* Initialize the I2C master peripheral */
I2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, I2C_MASTER_CLOCK_FREQUENCY);
/* Create the I2C handle for the non-blocking transfer */
I2C_MasterTransferCreateHandle(EXAMPLE_I2C_MASTER, &g_m_handle, i2c_master_callback, NULL);
while(1) {
PRINTF("Press return to receive from slave:");
GETCHAR();
PRINTF("Read:");
/* subAddress = 0x01, data = g_master_rxBuff - read from slave.
start + slaveaddress(w) + subAddress + repeated start + slaveaddress(r) + rx data buffer + stop */
masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;
masterXfer.direction = kI2C_Read;
masterXfer.subaddress = 0; /* changed to 0 */
masterXfer.subaddressSize = 0; /* changed to 0 */
masterXfer.data = g_master_rxBuff;
masterXfer.dataSize = 1; /* changed to 1 */
masterXfer.flags = kI2C_TransferDefaultFlag;
reVal = I2C_MasterTransferNonBlocking(EXAMPLE_I2C_MASTER, &g_m_handle, &masterXfer);
/* Reset master completion flag to false. */
g_MasterCompletionFlag = false;
if (reVal != kStatus_Success)
{
PRINTF("error\n");
while(1) { }
}
/* Wait for transfer completed. */
while (!g_MasterCompletionFlag)
{
}
PRINTF(" status:%i = %x\n", transfer_status, transfer_status);
g_MasterCompletionFlag = false;
}
}