LPI2C comunication query

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

LPI2C comunication query

1,601 Views
lesmesdanielpeñ
Contributor I

Hi, Im triying to configure a LPI2C comunication in a S32K144EVB-Q100 with S32 Design Studio but i don´t know how to do it.

The thing that i want to do is:

Master sends one byte (0x00) to the register 0x03 of one Slave with adress 0x6C.

The steps that i followed were: 

-I create a new Proyect.

-I run the Processor Expert and i add the driver of LPI2C.

-I configured LPI2C driver:

   *Slave adress: 0x6C 

   *Operating Mode:  Standard

   *Baud rate (Hz): 100000

   *Transfer Type: Interrupts

   

-I configured pins in the pin _mux

      PTA 2 -> SDA

      PTA3 -> SCL

- I use this code:

#include "Cpu.h"
#include "pin_mux.h"
#include "clockMan1.h"
#include "lpi2c1.h"
#include "dmaController1.h"
#include "osif1.h"
#include "lpi2c_driver.h"
#include "lpi2c1.h"

volatile int exit_code = 0;

lpi2c_master_state_t MasterState0={};
/*!

void disable_WDOG (void){
WDOG->CNT=0xD928C520; /*Unlock watchdog*/
WDOG->TOVAL=0x0000FFFF; /*Maximum timeout value*/
WDOG->CS = 0x00002100; /*Disable watchdog*/
}

void init_clock(void){
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

}


void init_pins(void){
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
}

void lpi2c1_MasterCallback0(uint8_t instance,lpi2c_master_event_t masterEvent,void *userData){};

int main(void)
{
/* Write your local variable definition here */

/*** 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. ***/
/* Write your code here */
disable_WDOG();
init_clock();
init_pins();

for(;;){

LPI2C_DRV_MasterInit(INST_LPI2C1,&lpi2c1_MasterConfig0,&MasterState0);


LPI2C_DRV_MasterSendData(INST_LPI2C1,0x00,1U,1);

LPI2C_DRV_MasterSendData(INST_LPI2C1,0x00,1U,1);

LPI2C_DRV_MasterDeinit(INST_LPI2C1);

}
/* For example: for(;;) { } */

/*** 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!!! ***/

-I connect to the SDA and SCL pins a osciloscope to see the signal and i dont receive nothing.

What i'm doing wrong?

Regards 

0 Kudos
3 Replies

776 Views
AlinaB
NXP Employee
NXP Employee

Hi,

I observed that you are using send non-blocking function followed by another send non-blocking and then you deinit the driver. When using non-blocking functions we must ensure that the current transfer ended before starting a new one. You can either use the blocking counterparts (e.g LPI2C_DRV_MasterSendDataBlocking) or ensure that driver has ended the transfer by using LPI2C_DRV_MasterGetTrasferStatus.

Another thing that I observed are the parameters you are using for MasterSendData function. The master will not send the byte 0x00 as you wish, it will send the value found at the address 0x00.

1. Example of how to use blocking functions:

/* Define transfer size */
#define TRANSFER_SIZE 8U

/* Define txBuffer */
uint8_t txBuffer[TRANSFER_SIZE] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7};

status_t retCode;

/* .... */

LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, txBuffer, TRANSFER_SIZE, true, 0xFFFF); /* where last parameter represents the timeout */

LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, txBuffer, TRANSFER_SIZE, true, 0xFFFF); /* where last parameter represents the timeout */


2. Example of how to use non-blocking functions:

LPI2C_DRV_MasterSendData(INST_LPI2C1, txBuffer, TRANSFER_SIZE, true);

/* Waiting the transfer to end before starting a new transfer*/
while ((retCode = LPI2C_DRV_MasterGetTransferStatus(INST_LPI2C1, NULL)) == STATUS_BUSY){}

LPI2C_DRV_MasterSendData(INST_LPI2C1, txBuffer, TRANSFER_SIZE, true);


I'm also curious of how the SCL and SDA signals look. Can you provide a capture of your SDA and SCL signals?

Best regards,
Alina

0 Kudos

776 Views
lesmesdanielpeñ
Contributor I

Hi,

First of all, thank you for answering me. I followed your steps and i have some more doubts...

-How can i choose the register of the slave to send data? 

-What do you mean when you say "The master will not send the byte 0x00 as you wish, it will send the value found at the address 0x00."? Is 0x0 defined in the txBuffer? Is the 0x0 adress of the master? How can i write data in that adress to send it to the slave?

I provide a capture of the SDA and SCL signals of my osciloscope. The top one is SDA and the bottom one is the SCL.pastedImage_1.jpg

Best regards

0 Kudos

776 Views
AlinaB
NXP Employee
NXP Employee

Hi,

1. From master side you can't choose the register of the slave to send data. What slave are you using?

2. I observed in your code that you called MasterSendData like this "LPI2C_DRV_MasterSendData(INST_LPI2C1,0x00,1U,1)" --> the second parameter is the master tx buffer address;

This is an example of code in which a lpi2c master is sending 0x0 to a slave with the address 0x6C:

#define TRANASFER_SIZE 1U
uint8_t txBuffer[TRANSFER_SIZE] = {0x0}

/* ..... */
/* Configure pins, clock, init master...*/

/* Optional you can use LPI2C_DRV_MasterSetSlaveAddr if you didn't configured the slave address using Processor Expert */
LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1, 0x6C, false);

LPI2C_DRV_MasterSendData(INST_LPI2C1, txBuffer, TRANSFER_SIZE, true);
/* Waiting the transfer to end before starting a new transfer*/
while ((retCode = LPI2C_DRV_MasterGetTransferStatus(INST_LPI2C1, NULL)) == STATUS_BUSY){}

/* ..... */

3. From the capture I observed that not even start is generated. Are you using the internal pull-ups resistors? If yes, try with external pull-up resistors of about ~4.7KOhm each.

Best regards,
Alina

0 Kudos