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
1,379 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
1,352 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
1,353 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
%3CLINGO-SUB%20id%3D%22lingo-sub-1886934%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EI2C%20Scanner%20using%20Processor%20Expert%20for%20S32K146EVB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1886934%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHello%20I%20am%20working%20on%20I2C%20Scanner%20by%20using%20S32K146EVB%20using%20Processor%20Expert.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20able%20to%20initialize%20I2C%20and%20while%20reading%20the%20Acknowledge%2C%20it%20is%20giving%20a%20problem.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20attached%20my%20file%20for%20your%20kind%20reference..%3CBR%20%2F%3EI%20hope%20to%20hear%20from%20you%20soon..%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F201913%22%20target%3D%22_blank%22%3E%40VaneB%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F188029%22%20target%3D%22_blank%22%3E%40Senlent%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1888198%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20I2C%20Scanner%20using%20Processor%20Expert%20for%20S32K146EVB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1888198%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%20Nibesh%2C%3C%2FP%3E%0A%3CP%3ESorry%20for%20not%20testing%20it%20for%20you%20in%20the%20previous%20question%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2FS32K%2FI2C-Scanner-using-S32K146EVB-Q144%2Fm-p%2F1881408%22%20target%3D%22_self%22%3EI2C%20Scanner%20using%20S32K146EVB-Q144%3C%2FA%3E.%20But%20as%20I%20mentioned%20there%2C%20since%20the%20%3CSTRONG%3ELPI2C_init%3C%2FSTRONG%3E%20of%20%3CSTRONG%3ES32K146_Project_LPI2C%3C%2FSTRONG%3E%20configure%20%3CSPAN%3EMCFGR1%5B%3C%2FSPAN%3E%3CSTRONG%3EIGNACK%3C%2FSTRONG%3E%5D%20to%20Ignore%20NACK%26nbsp%3Bby%20default%2C%20and%20its%20%3CSTRONG%3ELPI2C_Transmit%3C%2FSTRONG%3E%20uses%20MTDR%5B%3CSTRONG%3ECMD%3C%2FSTRONG%3E%5D%3D%3CSTRONG%3E5%3C%2FSTRONG%3E%20by%20default%3A%3CEM%3E101b%26nbsp%3B%20Generate%20(repeated)%20START%20and%20transmit%20address%20in%20DATA%5B7%3A0%5D.%20This%20transfer%20expects%20a%20NACK%20to%20be%20returned.%3C%2FEM%3E%3CBR%20%2F%3ESo%20you%20can't%20judge%20the%20acknowledgement%20by%20polling%20MSR%5BNDF%5D(NACK%20Detect%20Flag).%3C%2FP%3E%0A%3CP%3EPlease%20try%20to%20test%20the%20following%20code%3A%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3Evoid%20LPI2C_Transmit%20(uint8_t%20address)%2F*%20Transmit%20ID%20and%20expects%20an%20ACK%20to%20be%20returned%20*%2F%3CBR%20%2F%3E%7B%3CBR%20%2F%3ELPI2C0-%26gt%3BMTDR%20%3D%20(0x04%26lt%3B%26lt%3B8)%7C((address%26lt%3B%26lt%3B1)%7C0)%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CBR%20%2F%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3ELPI2C_DRV_MasterInit(0%2C%20%26amp%3Blpi2c1_MasterConfig0%2C%20%26amp%3Blpi2c1MasterState)%3B%3CBR%20%2F%3ELPI2C0-%26gt%3BMCFGR1%20%7C%3D%20LPI2C_MCFGR1_AUTOSTOP_MASK%3B%20%2F%2FAutomatic%20STOP%20Generation%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CBR%20%2F%3E%0A%3CBLOCKQUOTE%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bfor(i%3D1%3B%20i%26lt%3B127%3B%20i%2B%2B)%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7B%3C%2FDIV%3E%0A%3CDIV%3E%2F%2F%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BLPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1%2C%20i%2C%20false)%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BLPI2C_Transmit(i)%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bdelay(100)%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if((((LPI2C0-%26gt%3BMSR)%20%26amp%3B%20LPI2C_MSR_NDF_MASK)%20%26gt%3B%26gt%3B%20LPI2C_MSR_NDF_SHIFT)%3D%3Dtrue)%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20LPI2C0-%26gt%3BMSR%20%26amp%3B%3D%20LPI2C_MSR_NDF_MASK%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20LPUART_DRV_SendDataBlocking(INST_LPUART2%2C%20Space%2C%20sizeof(Space)%2C%20TIMEOUT)%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20else%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%20sprintf(%20Buffer%2C%220x%25X%22%2C%20i)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%20LPUART_DRV_SendDataBlocking(INST_LPUART2%2C%20Buffer%2C%20sizeof(Buffer)%2C%2010000)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7D%3C%2FDIV%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3EBest%20Regards%2C%3CBR%20%2F%3ERobin%3CBR%20%2F%3E-------------------------------------------------------------------------------%3CBR%20%2F%3ENote%3A%3CBR%20%2F%3E-%20If%20this%20post%20answers%20your%20question%2C%20please%20click%20the%20%22Mark%20Correct%22%20button.%20Thank%20you!%3C%2FP%3E%0A%3CP%3E-%20We%20are%20following%20threads%20for%207%20weeks%20after%20the%20last%20post%2C%20later%20replies%20are%20ignored%3CBR%20%2F%3EPlease%20open%20a%20new%20thread%20and%20refer%20to%20the%20closed%20one%2C%20if%20you%20have%20a%20related%20question%20at%20a%20later%20point%20in%20time.%3CBR%20%2F%3E-------------------------------------------------------------------------------%3C%2FP%3E%3C%2FLINGO-BODY%3E