LP I2C Transfer doesn't work

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LP I2C Transfer doesn't work

ソリューションへジャンプ
1,633件の閲覧回数
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,612件の閲覧回数
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)
2 返答(返信)
431件の閲覧回数
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,613件の閲覧回数
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)