I2C Scanner using Processor Expert for S32K146EVB

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

I2C Scanner using Processor Expert for S32K146EVB

Jump to solution
298 Views
Nibesh
Contributor III

Hello I am working on I2C Scanner by using S32K146EVB using Processor Expert.

I am able to initialize I2C and while reading the Acknowledge, it is giving a problem.

I have attached my file for your kind reference..
I hope to hear from you soon..
@VaneB @Senlent 

0 Kudos
Reply
1 Solution
271 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Nibesh,

Sorry for not testing it for you in the previous question I2C Scanner using S32K146EVB-Q144. But as I mentioned there, since the LPI2C_init of S32K146_Project_LPI2C configure MCFGR1[IGNACK] to Ignore NACK by default, and its LPI2C_Transmit uses MTDR[CMD]=5 by default:101b  Generate (repeated) START and transmit address in DATA[7:0]. This transfer expects a NACK to be returned.
So you can't judge the acknowledgement by polling MSR[NDF](NACK Detect Flag).

Please try to test the following code:

void LPI2C_Transmit (uint8_t address)/* Transmit ID and expects an ACK to be returned */
{
LPI2C0->MTDR = (0x04<<8)|((address<<1)|0);
}

 

LPI2C_DRV_MasterInit(0, &lpi2c1_MasterConfig0, &lpi2c1MasterState);
LPI2C0->MCFGR1 |= LPI2C_MCFGR1_AUTOSTOP_MASK; //Automatic STOP Generation

 

       for(i=1; i<127; i++)
       {
//       LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1, i, false);
       LPI2C_Transmit(i);
       delay(100);
        if((((LPI2C0->MSR) & LPI2C_MSR_NDF_MASK) >> LPI2C_MSR_NDF_SHIFT)==true)
        {
        LPI2C0->MSR &= LPI2C_MSR_NDF_MASK;
        LPUART_DRV_SendDataBlocking(INST_LPUART2, Space, sizeof(Space), TIMEOUT);
        }
        else
        {
sprintf( Buffer,"0x%X", i);
LPUART_DRV_SendDataBlocking(INST_LPUART2, Buffer, sizeof(Buffer), 10000);
        }
       }

Best Regards,
Robin
-------------------------------------------------------------------------------
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
1 Reply
272 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Nibesh,

Sorry for not testing it for you in the previous question I2C Scanner using S32K146EVB-Q144. But as I mentioned there, since the LPI2C_init of S32K146_Project_LPI2C configure MCFGR1[IGNACK] to Ignore NACK by default, and its LPI2C_Transmit uses MTDR[CMD]=5 by default:101b  Generate (repeated) START and transmit address in DATA[7:0]. This transfer expects a NACK to be returned.
So you can't judge the acknowledgement by polling MSR[NDF](NACK Detect Flag).

Please try to test the following code:

void LPI2C_Transmit (uint8_t address)/* Transmit ID and expects an ACK to be returned */
{
LPI2C0->MTDR = (0x04<<8)|((address<<1)|0);
}

 

LPI2C_DRV_MasterInit(0, &lpi2c1_MasterConfig0, &lpi2c1MasterState);
LPI2C0->MCFGR1 |= LPI2C_MCFGR1_AUTOSTOP_MASK; //Automatic STOP Generation

 

       for(i=1; i<127; i++)
       {
//       LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1, i, false);
       LPI2C_Transmit(i);
       delay(100);
        if((((LPI2C0->MSR) & LPI2C_MSR_NDF_MASK) >> LPI2C_MSR_NDF_SHIFT)==true)
        {
        LPI2C0->MSR &= LPI2C_MSR_NDF_MASK;
        LPUART_DRV_SendDataBlocking(INST_LPUART2, Space, sizeof(Space), TIMEOUT);
        }
        else
        {
sprintf( Buffer,"0x%X", i);
LPUART_DRV_SendDataBlocking(INST_LPUART2, Buffer, sizeof(Buffer), 10000);
        }
       }

Best Regards,
Robin
-------------------------------------------------------------------------------
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