I2C DEFAULT DRIVER NOT WORKING -LPC 55S16 MCU

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C DEFAULT DRIVER NOT WORKING -LPC 55S16 MCU

384 Views
Arularasan
Contributor II

Dear NXP Community,

I am writing to report an issue with the  I2C default driver. Specifically, the driver is not working for Flexcomm-6, SDA (Port 1, Pin 13) and SCL (Port 1, Pin 16) pins.

I have checked the hardware connections and verified the pin configuration, but the issue persists.I am using the LPC55S16 MCU, and I have consulted the datasheet for the correct pin configuration. I have also updated to the latest version of the NXP Flexcomm 6 I2C driver, but the issue remains.I would appreciate any assistance in resolving this issue. Please let me know if there are any known solutions or workarounds for this problem. Thank you for your attention to this matter. 

I HVAE ATTACHED THE CODE BELOW

Best regards,
ARULARASAN E

/*

* Copyright 2017 NXP

* All rights reserved.

*

* SPDX-License-Identifier: BSD-3-Clause

*/

 

/* Standard C Included Files */

#include <stdio.h>

#include <string.h>

#include "pin_mux.h"

#include "board.h"

#include "fsl_debug_console.h"

#include "fsl_i2c.h"

 

#include "fsl_power.h"

/*******************************************************************************

* Definitions

******************************************************************************/

#define EXAMPLE_I2C_MASTER_BASE (I2C6_BASE)

#define I2C_MASTER_CLOCK_FREQUENCY (12000000)

#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)

 

#define I2C_MASTER_SLAVE_ADDR_7BIT (0xA6U)

#define I2C_BAUDRATE (100000) /* 100K */

#define I2C_DATA_LENGTH (2) /* 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;

 

/*******************************************************************************

* 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. */

if (status == kStatus_Success)

{

g_MasterCompletionFlag = true;

}

}

 

/*!

* @brief Main function

*/

int main(void)

{

i2c_master_transfer_t masterXfer = {0};

status_t reVal = kStatus_Fail;

 

/* set BOD VBAT level to 1.65V */

POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);

/* attach 12 MHz clock to FLEXCOMM0 (debug console) */

CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

 

/* attach 12 MHz clock to FLEXCOMM8 (I2C master) */

CLOCK_AttachClk(kFRO12M_to_FLEXCOMM6);

 

/* reset FLEXCOMM for I2C */

RESET_PeripheralReset(kFC6_RST_SHIFT_RSTn);

 

BOARD_InitBootPins();

BOARD_InitBootClocks();

BOARD_InitDebugConsole();

 

PRINTF("\r\nI2C board2board interrupt example -- Master transfer.\r\n");

 

/* Set up i2c master to send data to slave*/

/* First data in txBuff is data length of the transmiting data. */

g_master_txBuff[0] = I2C_DATA_LENGTH - 1U;

for (uint32_t i = 1U; i < I2C_DATA_LENGTH; i++)

{

g_master_txBuff[i] = i - 1;

}

 

PRINTF("Master will send data :");

for (uint32_t i = 0U; i < I2C_DATA_LENGTH - 1U; i++)

{

if (i % 8 == 0)

{

PRINTF("\r\n");

}

PRINTF("0x%2x ", g_master_txBuff[i + 1]);

}

PRINTF("\r\n\r\n");

 

i2c_master_config_t masterConfig;

 

/*

* masterConfig.debugEnable = false;

* masterConfig.ignoreAck = false;

* masterConfig.pinConfig = kI2C_2PinOpenDrain;

* masterConfig.baudRate_Bps = 100000U;

* masterConfig.busIdleTimeout_ns = 0;

* masterConfig.pinLowTimeout_ns = 0;

* masterConfig.sdaGlitchFilterWidth_ns = 0;

* masterConfig.sclGlitchFilterWidth_ns = 0;

*/

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);

 

/* subAddress = 0x01, data = g_master_txBuff - write to slave.

start + slaveaddress(w) + subAddress + length of data buffer + data buffer + stop*/

uint8_t deviceAddress = 0x01U;

masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;

masterXfer.direction = kI2C_Write;

masterXfer.subaddress = (uint32_t)deviceAddress;

masterXfer.subaddressSize = 1;

masterXfer.data = g_master_txBuff;

masterXfer.dataSize = I2C_DATA_LENGTH;

masterXfer.flags = kI2C_TransferDefaultFlag;

 

/* Send master non-blocking data to slave */

reVal = I2C_MasterTransferNonBlocking(EXAMPLE_I2C_MASTER, &g_m_handle, &masterXfer);

 

/* Reset master completion flag to false. */

g_MasterCompletionFlag = false;

 

if (reVal != kStatus_Success)

{

return -1;

}

 

/* Wait for transfer completed. */

while (!g_MasterCompletionFlag)

{

}

g_MasterCompletionFlag = false;

 

PRINTF("Receive sent data from slave :");

 

/* 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 = (uint32_t)deviceAddress;

masterXfer.subaddressSize = 1;

masterXfer.data = g_master_rxBuff;

masterXfer.dataSize = I2C_DATA_LENGTH - 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)

{

return -1;

}

 

/* Wait for transfer completed. */

while (!g_MasterCompletionFlag)

{

}

g_MasterCompletionFlag = false;

 

for (uint32_t i = 0U; i < I2C_DATA_LENGTH - 1; i++)

{

if (i % 8 == 0)

{

PRINTF("\r\n");

}

PRINTF("0x%2x ", g_master_rxBuff[i]);

}

PRINTF("\r\n\r\n");

 

/* Transfer completed. Check the data.*/

for (uint32_t i = 0U; i < I2C_DATA_LENGTH - 1; i++)

{

if (g_master_rxBuff[i] != g_master_txBuff[i + 1])

{

PRINTF("\r\nError occurred in the transfer ! \r\n");

break;

}

}

 

PRINTF("\r\nEnd of I2C example .\r\n");

while (1)

{

}

}

 

0 Kudos
Reply
1 Reply

367 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

First of all, what is your issue? you did not clarify it in the description.

Can you tell the package of the LPC55S16? do you use PIO0_11 as FC6_SDA pin, PIO0_12 as FC6_SCL pin? If it is the case, do you assign the function in the pin_mux.c with the code like:

Do you connect external pull-up resistor on the SCL and SDA pins?

 

void BOARD_InitPins(void)

{

/* Enables the clock for the I/O controller.: Enable Clock. */

CLOCK_EnableClock(kCLOCK_Iocon);

 

const uint32_t port0_pin11_config = (/* Pin is configured as FC6_RXD_SDA_MOSI_DATA */

IOCON_PIO_FUNC1 |

/* No addition pin function */

IOCON_PIO_MODE_INACT |

/* Standard mode, output slew rate control is enabled */

IOCON_PIO_SLEW_STANDARD |

/* Input function is not inverted */

IOCON_PIO_INV_DI |

/* Enables digital function */

IOCON_PIO_DIGITAL_EN |

/* Open drain is disabled */

IOCON_PIO_OPENDRAIN_DI |

IOCON_PIO_ASW0_DI

);

/* PORT0 PIN11 (coords: 92) is configured as FC6_RXD_SDA_MOSI_DATA */

IOCON_PinMuxSet(IOCON, 0U, 11U, port0_pin11_config);

 

.

}

 

 

 

 

xiangjun_rong_0-1707196001109.png

Hope it can help you

BR

XiangJun Rong

 

0 Kudos
Reply