I2C Scanner using Processor Expert for S32K146EVB

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

I2C Scanner using Processor Expert for S32K146EVB

跳至解决方案
1,370 次查看
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 项奖励
回复
1 解答
1,343 次查看
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 项奖励
回复
1 回复
1,344 次查看
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 项奖励
回复
%3CLINGO-SUB%20id%3D%22lingo-sub-1886934%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%E4%BD%BF%E7%94%A8%E5%A4%84%E7%90%86%E5%99%A8%E4%B8%93%E5%AE%B6%E7%9A%84S32K146EVB%20I2C%E6%89%AB%E6%8F%8F%E4%BB%AA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1886934%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E6%82%A8%E5%A5%BD%EF%BC%8C%E6%88%91%E6%AD%A3%E5%9C%A8%E4%BD%BF%E7%94%A8%20Processor%20Expert%20%E4%BD%BF%E7%94%A8%20S32K146EVB%20%E5%BC%80%E5%8F%91%20I2C%20%E6%89%AB%E6%8F%8F%E4%BB%AA%E3%80%82%3CBR%20%2F%3E%3CBR%20%2F%3E%E6%88%91%E8%83%BD%E5%A4%9F%E5%88%9D%E5%A7%8B%E5%8C%96%20I2C%EF%BC%8C%E4%BD%86%E5%9C%A8%E8%AF%BB%E5%8F%96%E7%A1%AE%E8%AE%A4%E6%97%B6%EF%BC%8C%E5%87%BA%E7%8E%B0%E4%BA%86%E9%97%AE%E9%A2%98%E3%80%82%3CBR%20%2F%3E%3CBR%20%2F%3E%E6%88%91%E5%B7%B2%E9%99%84%E4%B8%8A%E6%88%91%E7%9A%84%E6%96%87%E4%BB%B6%E4%BE%9B%E6%82%A8%E5%8F%82%E8%80%83%E3%80%82%3CBR%20%2F%3E%E6%88%91%E5%B8%8C%E6%9C%9B%E5%BE%88%E5%BF%AB%E6%94%B6%E5%88%B0%E6%82%A8%E7%9A%84%E5%9B%9E%E5%A4%8D%E3%80%82%3CBR%20%2F%3E%20%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%20%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%3C%2FP%3E%3C%2FLINGO-BODY%3E