Hi,
I'm trying to configure LPI2C_0 in master mode. I tried to look out for the examples in the Autosar RTD example section, but there the I2C pins are configured using Flex IO.
I'm trying to interface DS3231 RTC with the controller using LPI2C channel 0 in master mode.
Any help is appreciated,
Regards,
Pratik
Hi @pratik_a,
You can use the following post as guidance: Example S32K312 I2C Transmit & Receive Using DMA DS3.5 RTD300 - NXP Community
It configures two instances for LPI2C as master-slave. You can see the transmission by measuring the SDA pin:
Best regards,
Julián
The example portrays I2C configuration using the non-autosar method whereas I want to go ahead with the Autosar way of implementing I2C communications.
Please help.
Regards,
Pratik
Hi @pratik_a,
The I2c_Example_S32K344 uses one instance as LPI2C and another one as I2C_FlexIO. You can create a new project for the S32K322 derivative and port over the example, changing it so it uses two I2C instances and changing the respective pins, as well as disabling FlexIO for the I2C module:
I have made a quick test with the S32K344 EVB:
Best regards,
Julián
Hi @Julián_AragónM ,
I have connected DS3231 RTC IC as a slave to the LPI2C0 of S32K322. So, I'm trying to configure LPI2C0 in the master mode. As instructed by you in the above post I disabled the flex IO and configured the LPI2C0 in the master mode, but I'm getting an error for baud rate as can be seen in the image.
Kindly help.
Regards,
Pratik
Hi @pratik_a,
Modify the value of I2c Clock High Period (CLKHI) and I2c Clock Low Period (CLKLO). The I2c Baud Rate will be automatically calculated based on your input value and will be displayed there. This is because of the I2C mode you are using (LPI2C_STANDARD_MODE) the upper limit has been exceeded.
You can find how the timing parameters are calculated from Table 440 from the S32K3xx Reference Manual:
Best regards,
Julián
Hi @Julián_AragónM ,
Thank you for providing continuous support. So, I changed the parameters of CLKHI and CLKLO as per the reference manual.
For standard mode and 8MHz core clock, I set the parameters as seen in the image above, but I'm getting a different baud rate as compared to what is mentioned in the manual. I'm trying to achieve 100Kbps baud rate.
Also, I'm getting an error when I try to compile the code. I have configured only LPI2C0 and disabled flex IO.
THe error i'm facing is,
undefined reference to `LPI2C0_Master_IRQHandler'
I have attached a few images for your reference.
Kindly help,
Regards,
Pratik
Thank you for your continuous support. I'm grateful for your help.
I tried renaming the handler's name and the code compiled successfully, but I'm faced with a new problem. I'm using a PE micro multilink for debugging and I have placed two breakpoints at
Port_Init(NULL_PTR); and
Platform_Init(NULL_PTR);
so, whenever I press resume after "Port_Init(NULL_PTR);" my debugging terminates, and console gives following output.
P&E Semihosting Console
Connection closed by the GDB server.
I'm attaching my code for your reference.
Hi @pratik_a,
Could you share your Port configuration from the Peripherals tab in Config Tools? Could you also confirm the port pins are configured correctly?
It would also help if you stepped into the Port_Init function and locate where the program stops.
Best regards,
Julián
I have attached the port configuration screenshots.
Also, I stepped into the function and found that the program terminates in the if loop in the program below.
The code is from function,
static inline void Port_Ipw_Init_UnusedPins(const Port_ConfigType * pConfigPtr)
from file Port_Ipw.c
Regards,
Pratik
I should have better read the document, pardon my questions.
Well, that did solve the debugging issue. I'm still unable to get the I2C working. I checked the signals using a logic analyzer.
What am I missing out on?
Hi @pratik_a,
Sorry for the delay. Looking into your slave's datasheet, it seems the SCL line supports up to Fast-mode (400kbit/s). Could this be the issue? Please test with this baudrate configuration.
Best regards,
Julián
Thank you for your continuous support.
I checked the datasheet of DS 3231 it supports 100kHz in normal mode and up to 400kHz in fast mode. I also tried adjusting the baud rate by doing the following settings,
I still don't get any output, not even on the clock line.
Can you check my code once for any errors.
Regards,
Pratik
Hi @pratik_a,
Sorry, it seems everything is correct when I checked your code. I'm not sure why there are no line generation, could you test another I2C instance or other pins to test HW as well?
Best regards,
Julián
I'm unable to get any signals on SDA or the SCL line when I connect the logic analyzer to it.
I have done all the settings according to the tutorial. Please go through my ode if I have done anything wrong,
I tried debugging the I2c_Init(NULL_PTR); function and when I step in I believe CoreId = (uint8) I2c_GetCoreID(); function returns 0. I'm using core 1 of the NXP S32K322 and my slave is a DS3231 RTC chip with a slave address 0x68. Let me know if that is the issue or if I'm missing out on something else.
Regards,
Pratik