How to set up register address with S32K118

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

How to set up register address with S32K118

Jump to solution
1,509 Views
allen90310
Contributor I

I want to use the function of I2C with S32K118. I've set up the slave address but I have no idea how to set up register address with slave address.

0 Kudos
Reply
1 Solution
1,478 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@allen90310

For example: Set Slave Address = 0x27,

1.Configure slave Address 0x27 (Slave address,7-bit or 10-bit) in Ipi2c1.h

lpi2c_slave_user_config_t lpi2c1_SlaveConfig0 = {
  .slaveAddress = 39U,//0x27
  .is10bitAddr = false,
  .slaveListening = true,
  .operatingMode = LPI2C_STANDARD_MODE,
  .transferType = LPI2C_USING_INTERRUPTS,
  .dmaChannel = 0U,
  .slaveCallback = lpi2c1_SlaveCallback0,
  .callbackParam = NULL,
};

 

2.Use "LPI2C_DRV_SlaveInit(INST_LPI2C1, &lpi2c1_SlaveConfig0, &lpi2c1SlaveState);",it will call function" LPI2C_Set_SlaveAddr0();" and then set Slave address7-bit or 10-bit.

Senlent_2-1636423739972.png

3.Register value.

Senlent_0-1636423468291.png

BR!

    Jim,

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
3 Replies
1,489 Views
allen90310
Contributor I

Hi@Senlent,

      Thanks for your reply. I've found the example project. The example seems like just init the slave. I don't how to set up certain register address base on it. Could you explain more detail of the example?

Thanks,

Allen

0 Kudos
Reply
1,479 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@allen90310

For example: Set Slave Address = 0x27,

1.Configure slave Address 0x27 (Slave address,7-bit or 10-bit) in Ipi2c1.h

lpi2c_slave_user_config_t lpi2c1_SlaveConfig0 = {
  .slaveAddress = 39U,//0x27
  .is10bitAddr = false,
  .slaveListening = true,
  .operatingMode = LPI2C_STANDARD_MODE,
  .transferType = LPI2C_USING_INTERRUPTS,
  .dmaChannel = 0U,
  .slaveCallback = lpi2c1_SlaveCallback0,
  .callbackParam = NULL,
};

 

2.Use "LPI2C_DRV_SlaveInit(INST_LPI2C1, &lpi2c1_SlaveConfig0, &lpi2c1SlaveState);",it will call function" LPI2C_Set_SlaveAddr0();" and then set Slave address7-bit or 10-bit.

Senlent_2-1636423739972.png

3.Register value.

Senlent_0-1636423468291.png

BR!

    Jim,

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply
1,497 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@allen90310

       You can refer to example "lpi2c_slave_s32k118" in S32 DS, and this example shows the LPI2C Slave functionality. The purpose of this demo application is to show you the usage of the LPI2C module available on the S32K118 MCU as a \b slave using S32 SDK.

usage or detail please refer to lpi2c_slave.dox in project.

-----------------------------------------------------------------------------------------------------------------------------------------

/*!
 * @brief Configure the ADDR0 address for slave address match
 * 
 * This function configures the ADDR0 value which is used to validate the received 
 * slave address. In 10-bit mode, the first address byte is compared to 
 * { 11110, ADDR0[10:9] } and the second address byte is compared to ADDR0[8:1]. 
 * In 7-bit mode, the address is compared to ADDR0[7:1]
 * The formula used for address validation is configured with function 
 * LPI2C_Set_SlaveAddrConfig().
 * 
 * @param baseAddr  base address of the LPI2C module
 * @param addr  ADDR0 address for slave address match
 */
static inline void LPI2C_Set_SlaveAddr0(LPI2C_Type *baseAddr, uint16_t addr)
{
    uint32_t tmp = baseAddr->SAMR;
    tmp &= ~(LPI2C_SAMR_ADDR0_MASK);
    tmp |= LPI2C_SAMR_ADDR0(addr);
    baseAddr->SAMR = tmp;
}

 If you are using LPI2C as slave mode base on bare-metal, please refer to the SDK driver to modify the code as you need..

 

BR!

     Jim,

0 Kudos
Reply