s32k144 i2c test issue

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

s32k144 i2c test issue

2,581件の閲覧回数
alice_th
Contributor III

hello,

i tested with S32K144EVB board with i2c interface, and find i2c sck signal is so week

and also the i send 3 data, but seems only two data sent, and the data is not correct

i use the demo code, do some modify it, could you help to check it and attached is the source code.

alice_thanks_0-1685609541229.png

alice_thanks_1-1685609694855.png

/* Definition of the data transfer size */
#define TRANSFER_SIZE (3u)
 
/*! 
  \brief The main function for the project.
  \details The startup initialization sequence is the following:
 * - __start (startup asm routine)
 * - __init_hardware()
 * - main()
 *   - PE_low_level_init()
 *     - Common_Init()
 *     - Peripherals_Init()
*/
 
void i2c_test()
{
int count = 0;
int i;
uint8_t buffer[TRANSFER_SIZE];
while(1)
{
if(count > 1000)
{
count = 0;
}
if(count == 0)
{
/* Initialize the data buffer */
    for (i = 0u; i < TRANSFER_SIZE; i++)
    {
        buffer[i] = 0x55;
    }
 
    /* Send a packet of data to the bus slave */
    LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
 
    /* Clear the buffer to prepare it for the next operation */
    for (i = 0u; i < TRANSFER_SIZE; i++)
    {
        buffer[i] = 0u;
    }
 
    /* Request data from the bus slave */
    LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
}
count++;
 
}
 
}
 

int main(void)
{
/* Allocate memory for the LPI2C driver state structure */
lpi2c_master_state_t lpi2c1MasterState;

/* Declaration of the LPI2C transfer buffer */
uint8_t buffer[TRANSFER_SIZE];

/* Variable used for the loop that initializes the data buffer */
uint16_t i;

/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/

/* Initialize and configure clocks
* - Configure system clocks and dividers
* - Configure LPI2C clock gating
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

/* Initialize pins
* - Configure LPI2C pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

/* Initialize LPI2C Master configuration
* - Slave address 0x01
* - Fast operating mode, 400 KHz SCL frequency
* - See LPI2C components for configuration details
*/
LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0, &lpi2c1MasterState);
i2c_test();
while(1)
{
/* Initialize the data buffer */
for (i = 0u; i < TRANSFER_SIZE; i++)
{
buffer[i] = 0x55;
}

/* Send a packet of data to the bus slave */
LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);

/* Clear the buffer to prepare it for the next operation */
for (i = 0u; i < TRANSFER_SIZE; i++)
{
buffer[i] = 0u;
}

/* Request data from the bus slave */
LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);
}
/* End of the driver example */

/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

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

2,568件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Alice,

In general, the strength of the signal depends on the external pull-up resistor, Cload on the bus, and the type of pads used (GPIO or GPIO-HD (PCR[DSE] = 1) if configurable).

But in this case, it looks like an error of measurement, I don't see the GND level on the osciloscope.

Also, from the image, it is not clear whether the transfer was acknowledged by the slave device or not, can you zoom in on the ACK bit?

What status code the LPI2C_DRV_MasterSendDataBlocking() returns?

 

Thank you,

BR, Daniel

 

 

0 件の賞賛
返信

2,566件の閲覧回数
alice_th
Contributor III

the GND is connect with the osciloscope, i can capture spi waveform is good with the same GND.

the I2C not connect any slave, i just measure the waveform with osciloscope.

does the waveform is correct ?

0 件の賞賛
返信

2,557件の閲覧回数
danielmartynek
NXP TechSupport
NXP TechSupport

There must be a slave device on the bus, and the master must address the slave.

Otherwise the master will just send an address that will not get acknowledged, and the transfer will be terminated on NACK.

So, in the image you posted, the master is trying to address the slave twice.

Once in each of the transfer functions you have in the i2c_test() function:

LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);

LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, TRANSFER_SIZE, true, OSIF_WAIT_FOREVER);

 

Please refer to UM10204 I2C-bus specification and user manual

https://assets.nexperia.com/documents/user-manual/UM10204.pdf

 

Regards,

Daniel

0 件の賞賛
返信

2,551件の閲覧回数
alice_th
Contributor III

ok, thanks!

seems only write read the address to the bus as no slave device, no data send, i will tested with slave device if still have problem will come back, thank you!