Can’t send data on LPI2C4

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

Can’t send data on LPI2C4

521 次查看
Mike_B
Contributor III

Setup/background

  • MIMXRT1021CAG4A on custom PCB similar to MIMXRT1020-EVK
  • Trying to establish I2C communication between LPI2C4 acting as a master and a slave device with address 0x6E

My project and my code
I started by clicking “Create a new C/C++ project” in the Quickstart panel and then selecting “evkmimxrt1020” as my SDK.

Mike_B_0-1684344690414.png

I also made sure to include the LPI2C driver (version 2.4.1) in my project by selecting i2c on the Drivers tab.

Mike_B_1-1684344707882.png

I configured my pins as follows:

Mike_B_2-1684344730887.png

And then clicked Project Explorer > Open Peripherals and added a new LPI2C peripheral. I used the default settings except I changed the Peripheral from LPI2C1 to LPI2C4 and I changed the slave address to 0x6E.


I then wrote the following code:

/*
 */
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MIMXRT1021.h"
#include "fsl_debug_console.h"
#include "fsl_lpi2c.h"

/* Defines */
#define BUFFER_SIZE 1

/* Variables */
lpi2c_master_config_t masterConfig;
uint8_t status;
status_t result = kStatus_Success;
uint8_t txBuff[BUFFER_SIZE];


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

    PRINTF("MCP3424 Utility\n");

    /* Gets the default configuration for master. */
    LPI2C_MasterGetDefaultConfig(&masterConfig);

    /* Initializes the I2C master. */
    //LPI2C_MasterInit(base, masterConfig, sourceClock_Hz);
    LPI2C_MasterInit(LPI2C4_PERIPHERAL, &masterConfig, LPI2C4_CLOCK_FREQ);

    /* Sends a start and a slave address. */
    //LPI2C_MasterStart(base, address, dir);
    LPI2C_MasterStart(LPI2C4_PERIPHERAL, LPI2C4_MASTER_SLAVE_ADDRESS, kLPI2C_Write/kLPI2C_Read);


    /* Force the counter to be placed into memory. */
    volatile static int i = 0 ;
    /* Enter an infinite loop, just incrementing a counter. */
    while(1) {
        i++ ;
        /* 'Dummy' NOP to allow source level single stepping of
            tight while() loop */
        __asm volatile ("nop");
    }
    return 0 ;
}

 

Issue
I realize the code is not finished but shouldn’t LPI2C_MasterStart at least send the slave address? I thought so but when I run the code my scope shows nothing on the SDA line (it never goes low). I do see a 100 kHz clock signal on the SCL line however.

0 项奖励
回复
2 回复数

508 次查看
Mike_B
Contributor III

When calling LPI2C_MasterInit, I changed &masterConfig to &LPI2C4_masterConfig and now it appears the start condition is being transmitted on SDL. 

Mike_B_0-1684349274015.png

Yellow: SDL

Violet: SCL

However the slave address is still not being transmitted. I checked the return value of LPI2C_MasterStart and it is 0.

0 项奖励
回复

487 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @Mike_B,

I would recommend using our example code and modifying it to use the 4th instance of the LPI2C module to ensure the hardware side of the I2C communication is correct. This way you prevent starting from scratch on your application and this should ease the troubleshooting aspect you are currently going through.

BR,
Edwin.

0 项奖励
回复