s32k144 i2c write read

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

s32k144 i2c write read

1,971件の閲覧回数
alice_th
Contributor III

hello ,

when i use k144 board i2c with PTA2/A3

void main()
{
#define CONVERT_T  0xCC44
    /* Write your code here */
    lpi2c_master_state_t lpi2c1MasterState;
CLOCK_DRV_Init(&clockMan1_InitConfig0);
 
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
    
LPUART_DRV_Init(INST_LPUART_1, &lpUartState1, &lpuart_1_InitConfig0);
LPSPI_DRV_MasterInit(INST_LPSPI_1,&lpspi_1State,&lpspi_1_MasterConfig0);
    LPI2C_DRV_MasterInit(INST_LPI2C0, &lpi2c0_MasterConfig0,&lpi2c1MasterState);
    while(1)
    {
        uint8_t cmd[2]={(uint8_t)(CONVERT_T >>8), (uint8_t)(CONVERT_T & 0xFF)};
uint8_t ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C0, cmd, 2, true, OSIF_WAIT_FOREVER);
        printf("ret=%d\n\r",ret);
   #if 0
        uint8_t data[3]; 
        ret = LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C0, data, 3, true,OSIF_WAIT_FOREVER);
        printf("ret=%d,data[0]=%x,d[1]=%x,d[2]=%x\n\r",ret,data[0],data[1],data[2]);
        float iTemp=(uint16_t)data[0]<<8 | data[1];
        //printf("iTemp=%.4f\n\r",((float)iTemp/256.0 + 40.0));
   #endif
    }
    //as8579_set_clock();
INT_SYS_InstallHandler(PORTA_IRQn, PORTA_ISR, (isr_t *)0);
INT_SYS_EnableIRQ(PORTA_IRQn);
adc0_init();
 
}
the device addr is 0x44
when use
uint8_t cmd[2]={(uint8_t)(CONVERT_T >>8), (uint8_t)(CONVERT_T & 0xFF)};
uint8_t ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C0, cmd, 2, true, OSIF_WAIT_FOREVER);
        printf("ret=%d\n\r",ret);
i find the waveform like below,  it only send the addr 0x44
 
alice_th_0-1744708826625.png

 

but if send like this, you can see addr 0x44, 0xcc, 0x44 be send and also other data be send

uint8_t cmd[2]={(uint8_t)(CONVERT_T >>8), (uint8_t)(CONVERT_T & 0xFF)};
uint8_t ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C0, cmd, 3, true, OSIF_WAIT_FOREVER);
        printf("ret=%d\n\r",ret);
 alice_th_1-1744709008738.png

can you help to check , what is happend with i2c driver ?

lpi2c_master_user_config_t lpi2c0_MasterConfig0 = {
.slaveAddress = 68U,
.is10bitAddr = false,
.operatingMode = LPI2C_FAST_MODE,
.baudRate = 400000UL,
.transferType = LPI2C_USING_INTERRUPTS,
.dmaChannel = 0U,
.masterCallback = NULL,
.callbackParam = NULL
};

lpi2c_slave_user_config_t lpi2c0_SlaveConfig0 = {
.slaveAddress = 50U,
.is10bitAddr = false,
.operatingMode = LPI2C_STANDARD_MODE,
.slaveListening = true,
.transferType = LPI2C_USING_INTERRUPTS,
.dmaChannel = 0U,
.slaveCallback = NULL,
.callbackParam = NULL
};

{
.base = PORTA,
.pinPortIdx = 2U,
.pullConfig = PORT_INTERNAL_PULL_UP_ENABLED,
.driveSelect = PORT_LOW_DRIVE_STRENGTH,
.passiveFilter = false,
.mux = PORT_MUX_ALT3,
.pinLock = false,
.intConfig = PORT_DMA_INT_DISABLED,
.clearIntFlag = false,
.gpioBase = NULL,
.digitalFilter = false,
},
{
.base = PORTA,
.pinPortIdx = 3U,
.pullConfig = PORT_INTERNAL_PULL_UP_ENABLED,
.driveSelect = PORT_LOW_DRIVE_STRENGTH,
.passiveFilter = false,
.mux = PORT_MUX_ALT3,
.pinLock = false,
.intConfig = PORT_DMA_INT_DISABLED,
.clearIntFlag = false,
.gpioBase = NULL,
.digitalFilter = false,
},

0 件の賞賛
返信
6 返答(返信)

1,931件の閲覧回数
Senlent
NXP TechSupport
NXP TechSupport

Hi@alice_th

I test your project and the result is same.

Senlent_0-1744787964786.png

Senlent_1-1744787997617.png

 

0 件の賞賛
返信

1,928件の閲覧回数
alice_th
Contributor III

Hello @Senlent 

you didn't connect the device, if connect device, should have ACK from device.

when i remove OSIF_TimeDelay(20); or printf

uint8_t cmd[2]={(uint8_t)(CONVERT_T >>8), (uint8_t)(CONVERT_T & 0xFF)};
uint8_t ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C0, cmd, 2, true, OSIF_WAIT_FOREVER);
//printf("ret=%d\n\r",ret);
//OSIF_TimeDelay(20);
uint8_t data[3];
ret = LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C0, data, 3, true,OSIF_WAIT_FOREVER);

then waveform become below, it seems the send data is ok, why delay, or printf will influence i2c communicate ?

alice_th_0-1744791471203.png

 

 

0 件の賞賛
返信

1,912件の閲覧回数
Senlent
NXP TechSupport
NXP TechSupport

Hi@alice_th

This may be related to the features of your slave device, for example, whether it is necessary to perform a read operation within a fixed time after your write operation. You can use two S32K144 to directly simulate the master-slave operation of L2C, and we also have examples for reference, so you can check whether this problem may be caused by your slave device.

0 件の賞賛
返信

1,886件の閲覧回数
alice_th
Contributor III

Hello @Senlent 

there is no special after send for slave device, look at the spec when send complete, it should wait for the measurement, then read.

SCL空闲 ---> SCL IDLE

I2C 地址 ——> I2C address

指令高字节 ---> command MSB

指令低字节 ---> command LSB

alice_th_0-1744861717548.png

the wired thing is when add the delay after receive, it still same wrong waveform as before.

uint8_t cmd[2]={(uint8_t)(CONVERT_T >>8), (uint8_t)(CONVERT_T & 0xFF)};
uint8_t ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C0, cmd, 2, true, OSIF_WAIT_FOREVER);

uint8_t data[3];
ret = LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C0, data, 3, true,OSIF_WAIT_FOREVER);

//printf("ret=%d\n\r",ret);
OSIF_TimeDelay(20);

then waveform become below, it seems the send data is ok, why delay, or printf will influence i2c communicate ?

0 件の賞賛
返信

1,874件の閲覧回数
Senlent
NXP TechSupport
NXP TechSupport

Hi@alice_th

I don't have the sensor you used and tested, so I can't help you reproduce the problem.

But I am sure that this is related to the sensor.

For example, I tested a sensor and added "OSIF_TimeDelay" to it as you said.

I tested it in two ways and both met my expectations.

Test 1.

Senlent_0-1744877537607.png

Test 2.

Senlent_2-1744877915900.png

Senlent_1-1744877877992.png

You can see there is no probem on myside.

0 件の賞賛
返信

1,962件の閲覧回数
alice_th
Contributor III

please see attach code

when add OSIF_TimeDelay(20); the i2c also work wrong

please help to check it.

 

0 件の賞賛
返信