LP I2C Transfer doesn't work

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

LP I2C Transfer doesn't work

跳至解决方案
1,408 次查看
finalargasio
Contributor II

Dear NXP experts I seek your wisdom,

I have been trying to set up and use I2C to read a sensor on my MIMXRT1064-EVK without success.

The sensor works, it has proper pullups,and I have managed to read it with an Arduino board and a Nucleo board.

I have been trying to use the TransferBlocking api, but looking with an oscilloscope, there is no signal on the SDA nor SCL line.

By going step by step I see I get a kStatus_LPI2C_FifoError flag when LPI2C_MasterCheckAndClearError is called by LPI2C_MasterReceive

What am I doing wrong?

Here is my code, and below it, the initialization config screenshots

 

 

/**
 * @file    i2cTest.c
 * @brief   Application entry point.
 */
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MIMXRT1064.h"
#include "fsl_debug_console.h"
/* TODO: insert other include files here. */
#include  "fsl_lpi2c.h"
/* TODO: insert other definitions and declarations here. */
typedef struct _i2cTmpSnsStruct{
	uint8_t dataIn[10];

}i2cTmpSnsStruct;
i2cTmpSnsStruct myI2CSns;
lpi2c_master_transfer_t myI2CTransfer = {
		.slaveAddress = 0x68,
		.direction = kLPI2C_Read,
		.subaddress = 0x3B,
		.subaddressSize = 1,
		.data = myI2CSns.dataIn,
		.dataSize = 2,
		.flags = kLPI2C_TransferDefaultFlag,
};
volatile int count = 0;
void lpi2c_master_transfer_callback(LPI2C_Type *base, lpi2c_master_handle_t *handle, status_t completionStatus, void *userData){

	if(completionStatus == 900){
		count++;
	}
}
/*
 * @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


    static int returnCode = 0;
    static int myStatus = 0;
    /* Force the counter to be placed into memory. */
    volatile static int i = 0 ;
    /* Enter an infinite loop, just incrementing a counter. */
    while(1) {

    	LPI2C_MasterCheckAndClearError(LPI2C1, &myStatus);
    	returnCode = LPI2C_MasterTransferBlocking(LPI2C1,&myI2CTransfer);
    	LPI2C_MasterStop(LPI2C1);
    	//LPI2C_MasterTransferNonBlocking(LPI2C1,&BOARD_LPI2C1_masterHandle,&myI2CTransfer);
    	/* Delay*/
    	while(i < 1000000){
    		i++;
    	}
    	i = 0;
    }
    return 0 ;
}

 

 

i2c1.pngi2c2.pngi2c3.png

标签 (1)
0 项奖励
回复
1 解答
1,387 次查看
finalargasio
Contributor II

Hi all, I have managed to resolve my own problem, if somebody has this issue go to the pin configuration menu and make sure SCL and SDA configured in this way (image below), the configurator tool initializes these parameters in the wrong way, especially the "Software Input On"parameter which is essential and must be ON.

i2csol.png

I hope this will help,

Regards

在原帖中查看解决方案

标记 (1)
0 项奖励
回复
2 回复数
206 次查看
JKPAPER_DELOPT_SR
Contributor I

Thanks a ton for this post, I struggled with the code for 2 weeks and then finally found this. This solved my I2C problem.

Everything in the code was right and still I was unable to get the output, heartfelt thanks to you for this post and my colleague who found this post!

0 项奖励
回复
1,388 次查看
finalargasio
Contributor II

Hi all, I have managed to resolve my own problem, if somebody has this issue go to the pin configuration menu and make sure SCL and SDA configured in this way (image below), the configurator tool initializes these parameters in the wrong way, especially the "Software Input On"parameter which is essential and must be ON.

i2csol.png

I hope this will help,

Regards

标记 (1)
0 项奖励
回复