LP I2C Transfer doesn't work

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

LP I2C Transfer doesn't work

Jump to solution
1,773 Views
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

Labels (1)
0 Kudos
Reply
1 Solution
1,752 Views
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

View solution in original post

Tags (1)
2 Replies
571 Views
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 Kudos
Reply
1,753 Views
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

Tags (1)