Need help witn I2C code (using Peripheral Config Tool)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Need help witn I2C code (using Peripheral Config Tool)

跳至解决方案
3,276 次查看
simmania
Contributor IV

I need to use the I2C1 peripheral. I checked the example programs. But I must say that is not really example code. Because with example code I expect good comments explaining the why's and how's. But there is zero comments! As a programmer I would never write such code, and certainly not example code!

But what is worst, the examples do not use the Peripheral and Clock Config Tools while that is said to be the preferred way of working!

So I have to figure everything out myself. But without good examples that is hard. Very hard.

For instance: one can choose one of the modes: Polling, Interrupts, Transfer, eDMA and RTOS. Is there any explanation somewhere what they exactly mean?
Is a programmer I think I have an idea of Polling, Interrupt and eDMA. But what is Transfer? They all transfer data. And why is RTOS is separate mode. Isn't RTOS also eDMA or Interrupts?

If I choose one of these modes, which function am I supposed to use? Are those the same as the examples that are not based on the Peripheral Config Tools?

What is the expected way to find you way around?

(And please, please, please, give us example code that uses the Config Tools!)

0 项奖励
回复
1 解答
3,113 次查看
mayliu1
NXP Employee
NXP Employee

Hi @simmania ,

 

Thanks for your reply.

I did a validation as you do. 

I create a new project, and set pin in Config Tool, I use the I2C pins just as you do.

and copy driver files from  evkmimxrt1010_lpi2c_interrupt_b2b_transfer_master to the new project, also I copy code from evkmimxrt1010_lpi2c_interrupt_b2b_transfer_master.c to the new project file MIMXRT1011_Project.c

mayliu1_0-1732775516277.png

mayliu1_3-1732775731977.png

 

I use MIMXRT1064-EVK board as I 2C slave. 

mayliu1_1-1732775551564.png

I test that I2C can work normal.

mayliu1_2-1732775664674.jpeg

 

Wish it helps you.
If you still have question about it, please kindly let me know.

 

BR

mayliu

 

 

在原帖中查看解决方案

0 项奖励
回复
6 回复数
3,257 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi @simmania 

Please let us know your chip part number thus we can assign right engineer to answer your questions.

Thanks,

Jun Zhang

0 项奖励
回复
3,244 次查看
simmania
Contributor IV

I'm using the MIMXRT1010-EVK board.

I copied some code from the example 'evkmimxrt1010_lpi2c_interrupt_b2b_transfer_master' into a new project. I did configure the Pins, Clock and Peripheral for the LPI2C1 port with the config tools, so I removed that code from the main function. But it does not work. While the example project did work.

So what am I doing wrong?

The clock for the LPI2C is configured for 10MHz, The pins GPIO_01 and GPIO_02 are assigned to the LPI2C1. And the peripheral is configured as shown in the attached picture.

The main code is listed below.

Note that when I run this program I do see activity on the I2C lines. It looks like the start condition is generated and then immediately both lines go high and stay high. The interrupt routine is called with status != kStatus_Success. The value is 905, but I can not found out what that means.

#include <stdio.h>

#include "board.h"

#include "peripherals.h"

#include "pin_mux.h"

#include "clock_config.h"

#include "fsl_debug_console.h"

#include <string.h>

#include "fsl_lpi2c.h"

 

#define EXAMPLE_I2C_MASTER_BASE (LPI2C1_BASE)

#define EXAMPLE_I2C_MASTER ((LPI2C_Type *)EXAMPLE_I2C_MASTER_BASE)

#define I2C_MASTER_SLAVE_ADDR_7BIT 0x1AU

 

//

// Global variables

//

lpi2c_master_handle_t g_m_handle;

volatile bool g_MasterCompletionFlag = false;

volatile bool g_MasterNackFlag = false;

 

static void lpi2c_master_callback(LPI2C_Type *base, lpi2c_master_handle_t *handle, status_t status, void *userData)

{

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

 

if (status == kStatus_LPI2C_Nak)

{

    g_MasterNackFlag = true;

}

else

{

    g_MasterCompletionFlag = true;

    /* Display failure information when status is not success. */

    if (status != kStatus_Success)

    {

        PRINTF("\r\n*** Error occured during transfer! status = %d\r\n", status);

    }

}

}

 

/*

* @brief Application entry point.

*/

int main(void) {

 

/* Init board hardware. */

BOARD_ConfigMPU();

BOARD_InitBootPins();

BOARD_InitBootClocks();

BOARD_InitBootPeripherals();

#ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL

/* Init FSL debug console. */

BOARD_InitDebugConsole();

#endif

 

lpi2c_master_transfer_t masterXfer = {0};

status_t reVal = kStatus_Fail;

 

/* Create the LPI2C handle for the non-blocking transfer */

LPI2C_MasterTransferCreateHandle(EXAMPLE_I2C_MASTER, &g_m_handle, lpi2c_master_callback, NULL);

 

PRINTF("\r\nSend data to slave...\r\n");

 

uint8_t deviceAddress = 0x01U;

uint8_t data[1] = {0xAA};

masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;

masterXfer.direction = kLPI2C_Write;

masterXfer.subaddress = (uint32_t)deviceAddress;

masterXfer.subaddressSize = 1;

masterXfer.data = data;

masterXfer.dataSize = 1;

masterXfer.flags = kLPI2C_TransferDefaultFlag;

 

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

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

 

if (reVal != kStatus_Success)

{

    PRINTF("\r\nI2C transfer error!\r\n");

    return -1;

}

/* Wait for transfer completed. */

while ((!g_MasterCompletionFlag) && (!g_MasterNackFlag))

{

}

if (g_MasterNackFlag)

{

    PRINTF("- Master nacked by slave!\r\n");

    g_MasterNackFlag = false;

}

g_MasterCompletionFlag = false;

 

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

while (1)

{

}

return 0 ;

}

 

 

0 项奖励
回复
3,240 次查看
simmania
Contributor IV

Update:

When create a new project and copy the whole file with the main function of the working example into this new project, it gives the same problem!
So only a start condition on the I2C bus and then it stops.

What is different from a example and a new project that can cause this?

0 项奖励
回复
3,199 次查看
mayliu1
NXP Employee
NXP Employee

Hi @simmania ,

Thank you so much for your interest in our products and for using our community.

I'm sorry that you have  problem while using the NXP config tool.

I want to know did you copy  evkmimxrt1010_lpi2c_interrupt_b2b_transfer_master.mex file   into your new project?

mayliu1_1-1732507364517.png

If you change I2C pin, Please double check I2C PIN configuration. Especially  Software Input On and Open drain need to be set enable.

mayliu1_3-1732507752839.png

If you want to know more about NXP Config Tool, maybe you refer "MCUXpresso_IDE_ConfigTools_User_Guide.pdf",  This file is in your MCUXPresso IDE installed path.

mayliu1_4-1732508054467.png

Wish it helps you.
If you still have question about it, please kindly let me know.

 

Best Regards

mayliu

 

0 项奖励
回复
3,152 次查看
simmania
Contributor IV

No, I did not copy the mex file, but I configured the I2C IO pins properly and checked for correct clock in the Clock Config tool.

0 项奖励
回复
3,114 次查看
mayliu1
NXP Employee
NXP Employee

Hi @simmania ,

 

Thanks for your reply.

I did a validation as you do. 

I create a new project, and set pin in Config Tool, I use the I2C pins just as you do.

and copy driver files from  evkmimxrt1010_lpi2c_interrupt_b2b_transfer_master to the new project, also I copy code from evkmimxrt1010_lpi2c_interrupt_b2b_transfer_master.c to the new project file MIMXRT1011_Project.c

mayliu1_0-1732775516277.png

mayliu1_3-1732775731977.png

 

I use MIMXRT1064-EVK board as I 2C slave. 

mayliu1_1-1732775551564.png

I test that I2C can work normal.

mayliu1_2-1732775664674.jpeg

 

Wish it helps you.
If you still have question about it, please kindly let me know.

 

BR

mayliu

 

 

0 项奖励
回复