LPC55S28-EVK b2b I2C communication

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

LPC55S28-EVK b2b I2C communication

跳至解决方案
2,103 次查看
Marconi_
Contributor I

Dear all,

I'm using LPC55S28-EVK configured as slave to receive I2C data coming from master.

I'm using SDK example i2c_interrupt_b2b_transfer_slave.

It works but I don't know how to detect if received data is write or read command.

As you know I2C read or write command depends on the LSB of address. How to tetect it ?

Thank you very much for your help and cooperation

regards

标记 (1)
0 项奖励
回复
1 解答
2,081 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Marconi_ 

In I2C protocol, the LSB of the address byte is used to determine whether the command is a read or write operation. If the LSB is 0, it's a write operation; if it's 1, it's a read operation.

When you receive an interrupt indicating that data has been received, you can check the LSB of the address byte to determine whether it's a read or write operation.

Here's a simple example:

void I2C0_IRQHandler(void)
{

// Address match event occurred
uint8_t address = I2C0->ADDR;

// Check the LSB to determine read (1) or write (0)
if (address & 0x01)
{
// Read command (LSB is 1)
// Perform actions for read command
}
else
{
// Write command (LSB is 0)
// Perform actions for write command
}

}

Hope this will help you.

BR

Hang

 

在原帖中查看解决方案

0 项奖励
回复
1 回复
2,082 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @Marconi_ 

In I2C protocol, the LSB of the address byte is used to determine whether the command is a read or write operation. If the LSB is 0, it's a write operation; if it's 1, it's a read operation.

When you receive an interrupt indicating that data has been received, you can check the LSB of the address byte to determine whether it's a read or write operation.

Here's a simple example:

void I2C0_IRQHandler(void)
{

// Address match event occurred
uint8_t address = I2C0->ADDR;

// Check the LSB to determine read (1) or write (0)
if (address & 0x01)
{
// Read command (LSB is 1)
// Perform actions for read command
}
else
{
// Write command (LSB is 0)
// Perform actions for write command
}

}

Hope this will help you.

BR

Hang

 

0 项奖励
回复
%3CLINGO-SUB%20id%3D%22lingo-sub-1889289%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELPC55S28-EVK%20b2b%20I2C%E9%80%9A%E4%BF%A1%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1889289%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%E5%B0%8A%E6%95%AC%E7%9A%84%E5%90%84%E4%BD%8D%EF%BC%8C%3C%2FP%3E%3CP%3E%E6%88%91%E6%AD%A3%E5%9C%A8%E4%BD%BF%E7%94%A8%E9%85%8D%E7%BD%AE%E4%B8%BA%E4%BB%8E%E6%9C%BA%E7%9A%84%20LPC55S28-EVK%20%E6%9D%A5%E6%8E%A5%E6%94%B6%E6%9D%A5%E8%87%AA%E4%B8%BB%E6%9C%BA%E7%9A%84%20I2C%20%E6%95%B0%E6%8D%AE%E3%80%82%3C%2FP%3E%3CP%3E%E6%88%91%E6%AD%A3%E5%9C%A8%E4%BD%BF%E7%94%A8%20SDK%20%E7%A4%BA%E4%BE%8B%20i2c_interrupt_b2b_transfer_slave%E3%80%82%3C%2FP%3E%3CP%3E%E5%AE%83%E5%8F%AF%E4%BB%A5%E5%B7%A5%E4%BD%9C%EF%BC%8C%E4%BD%86%E6%88%91%E4%B8%8D%E7%9F%A5%E9%81%93%E5%A6%82%E4%BD%95%E6%A3%80%E6%B5%8B%E6%8E%A5%E6%94%B6%E5%88%B0%E7%9A%84%E6%95%B0%E6%8D%AE%E6%98%AF%E5%86%99%E5%85%A5%E5%91%BD%E4%BB%A4%E8%BF%98%E6%98%AF%E8%AF%BB%E5%8F%96%E5%91%BD%E4%BB%A4%E3%80%82%3C%2FP%3E%3CP%3E%E5%A6%82%E6%82%A8%E6%89%80%E7%9F%A5%EF%BC%8CI2C%20%E8%AF%BB%E5%8F%96%E6%88%96%E5%86%99%E5%85%A5%E5%91%BD%E4%BB%A4%E5%8F%96%E5%86%B3%E4%BA%8E%E5%9C%B0%E5%9D%80%E7%9A%84%20LSB%E3%80%82%E5%A6%82%E4%BD%95%E6%A3%80%E6%B5%8B%E5%AE%83%EF%BC%9F%3C%2FP%3E%3CP%3E%E9%9D%9E%E5%B8%B8%E6%84%9F%E8%B0%A2%E6%82%A8%E7%9A%84%E5%B8%AE%E5%8A%A9%E5%92%8C%E5%90%88%E4%BD%9C%3C%2FP%3E%3CP%3E%E6%AD%A4%E8%87%B4%E9%97%AE%E5%80%99%3C%2FP%3E%3C%2FLINGO-BODY%3E