Flexcomm1 I2C configuration

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

Flexcomm1 I2C configuration

251 Views
Nazmin
Contributor I

Hi Team,

I have been trying to configure I2C using Flexcomm1. I am not able to establish a connection between master and slave. I am trying to execute the same example code with changes. Following are the snapshot of the changes made in the sample code (SDK_2_11_1_EVK MIMXRT685\boards\evkmimxrt685\driver_examples\i2c\polling_b2b\master). in order to shift from FC4 to FC1.

#define GDY112X_I2C_BASE            I2C1
#define I2C1_MASTER_CLOCK_FREQUENCY  CLOCK_GetFlexCommClkFreq(1U)
#define GDY112X_I2C_BAUDRATE        (100000U)
/* GDY112X address (7-bit) */
#define GDY112X_7BIT_I2C_ADDR            (0x3A)
 
int main(void)
{
 
/* Init Flexcomm1 as I2C */
 i2c_master_config_t masterConfig;
I2C_MasterGetDefaultConfig(&masterConfig);
 
/* Change the default baudrate configuration */
masterConfig.baudRate_Bps = GDY112X_I2C_BAUDRATE;

/* Initialize the I2C master peripheral */
I2C_MasterInit(GDY112X_I2C_BASE, &masterConfig, I2C1_MASTER_CLOCK_FREQUENCY);
 
/*This function to write and read data from master to slave/slave from master/*
void GDY1121_MinimalI2CTest(void)
{
    status_t status;
    uint8_t reg = WHO_AM_I_REG;
    uint8_t whoami = 0;

    PRINTF("Starting minimal I2C test...\r\n");

 // 1) Send register address (write)
    status = I2C_MasterStart(GDY112X_I2C_BASE, GDY112X_7BIT_I2C_ADDR, kI2C_Write);
    if (status != kStatus_Success) {
        PRINTF("Start (write) failed, status=%d\r\n", status);
        return;
    }

    status = I2C_MasterWriteBlocking(GDY112X_I2C_BASE, &reg, 1, kI2C_TransferNoStopFlag);
    if (status != kStatus_Success) {
        PRINTF("Write reg addr failed, status=%d\r\n", status);
        I2C_MasterStop(GDY112X_I2C_BASE);
        return;
    }
 
// 2) Restart and read 1 byte
    status = I2C_MasterRepeatedStart(GDY112X_I2C_BASE, GDY112X_7BIT_I2C_ADDR, kI2C_Read);
    if (status != kStatus_Success) {
        PRINTF("Repeated start (read) failed, status=%d\r\n", status);
        I2C_MasterStop(GDY112X_I2C_BASE);
        return;
    }

    status = I2C_MasterReadBlocking(GDY112X_I2C_BASE, &whoami, 1, kI2C_TransferDefaultFlag);
    if (status != kStatus_Success) {
        PRINTF("Read WHO_AM_I failed, status=%d\r\n", status);
        I2C_MasterStop(GDY112X_I2C_BASE);
        return;
    }

    // 3) Stop
    I2C_MasterStop(GDY112X_I2C_BASE);

    PRINTF("WHO_AM_I read success: 0x%02X\r\n", whoami);
}

 

/* pin_mux.c/*

void BOARD_InitPins(void)
{
/* PIO0_8 : FC1_I2C_SCL */
    const uint32_t port0_pin8_config = (/* Pin is configured as FC1_TXD_SCL_MISO_WS*/
                                        IOPCTL_PIO_FUNC1 |
                                        /* Enable pull-up / pull-down function */
                                        IOPCTL_PIO_PUPD_EN |
                                        /* Enable pull-up function */
                                        IOPCTL_PIO_PULLUP_EN |
                                        /* Enables input buffer function */
                                        IOPCTL_PIO_INBUF_EN |
                                        /* Normal mode */
                                        IOPCTL_PIO_SLEW_RATE_NORMAL |
/* Normal drive */
                                        IOPCTL_PIO_FULLDRIVE_DI |
                                        /* Analog mux is disabled */
                                        IOPCTL_PIO_ANAMUX_DI |
                                        /* Pseudo Output Drain is disabled */
                                        IOPCTL_PIO_PSEDRAIN_DI |
                                        /* Input function is not inverted */
                                        IOPCTL_PIO_INV_DI);
    IOPCTL_PinMuxSet(IOPCTL, 0U, 8U, port0_pin8_config);
 
/* PIO0_9 : FC1_I2C_SDA */
    const uint32_t port0_pin9_config = (/* Pin is configured as FC1_RXD_SDA_MOSI_DATA */
                                        IOPCTL_PIO_FUNC1 |
                                        /* Enable pull-up / pull-down function */
                                        IOPCTL_PIO_PUPD_EN |
                                        /* Enable pull-up function */
                                        IOPCTL_PIO_PULLUP_EN |
                                        /* Enables input buffer function */
                                        IOPCTL_PIO_INBUF_EN |
/* Normal mode */
                                        IOPCTL_PIO_SLEW_RATE_NORMAL |
                                        /* Normal drive */
                                        IOPCTL_PIO_FULLDRIVE_DI |
                                        /* Analog mux is disabled */
                                        IOPCTL_PIO_ANAMUX_DI |
                                        /* Pseudo Output Drain is disabled */
                                        IOPCTL_PIO_PSEDRAIN_DI |
                                        /* Input function is not inverted */
                                        IOPCTL_PIO_INV_DI);
    IOPCTL_PinMuxSet(IOPCTL, 0U, 9U, port0_pin9_config);
}
 
After run, the system hang in function I2C_MasterTransferBlocking(). Please advise
0 Kudos
Reply
2 Replies

155 Views
Nazmin
Contributor I

Hi @Pablo_Ramos , this issue solved in ticket Case: 00737268.

Thanks

0 Kudos
Reply

177 Views
Pablo_Ramos
NXP Employee
NXP Employee

Hi Nazmin,

Could you help me with the following questions?

Do you see any outputs through the I2C pins? If you do, could you share a snippet?

In which instance does I2C_MasterTransferBlocking hang?

If you use the example without any changes, does it work?

Best Regards,

Pablo

0 Kudos
Reply