LPC55S28-EVK b2b I2C communication

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

LPC55S28-EVK b2b I2C communication

Jump to solution
1,392 Views
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

Tags (1)
0 Kudos
Reply
1 Solution
1,370 Views
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

 

View solution in original post

0 Kudos
Reply
1 Reply
1,371 Views
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 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-1889289%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ELPC55S28-EVK%20b2b%20I2C%20communication%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1889289%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EDear%20all%2C%3C%2FP%3E%3CP%3EI'm%20using%20LPC55S28-EVK%20configured%20as%20slave%20to%20receive%20I2C%20data%20coming%20from%20master.%3C%2FP%3E%3CP%3EI'm%20using%20SDK%20example%20i2c_interrupt_b2b_transfer_slave.%3C%2FP%3E%3CP%3EIt%20works%20but%20I%20don't%20know%20how%20to%20detect%20if%20received%20data%20is%20write%20or%20read%20command.%3C%2FP%3E%3CP%3EAs%20you%20know%20I2C%20read%20or%20write%20command%20depends%20on%20the%20LSB%20of%20address.%20How%20to%20tetect%20it%20%3F%3C%2FP%3E%3CP%3EThank%20you%20very%20much%20for%20your%20help%20and%20cooperation%3C%2FP%3E%3CP%3Eregards%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1891259%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20LPC55S28-EVK%20b2b%20I2C%20communication%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1891259%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F232835%22%20target%3D%22_blank%22%3E%40Marconi_%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20I2C%20protocol%2C%20the%20LSB%20of%20the%20address%20byte%20is%20used%20to%20determine%20whether%20the%20command%20is%20a%20read%20or%20write%20operation.%20If%20the%20LSB%20is%200%2C%20it's%20a%20write%20operation%3B%20if%20it's%201%2C%20it's%20a%20read%20operation.%3C%2FP%3E%0A%3CP%3EWhen%20you%20receive%20an%20interrupt%20indicating%20that%20data%20has%20been%20received%2C%20you%20can%20check%20the%20LSB%20of%20the%20address%20byte%20to%20determine%20whether%20it's%20a%20read%20or%20write%20operation.%3C%2FP%3E%0A%3CP%3EHere's%20a%20simple%20example%3A%3C%2FP%3E%0A%3CP%3Evoid%20I2C0_IRQHandler(void)%3CBR%20%2F%3E%7B%3C%2FP%3E%0A%3CP%3E%2F%2F%20Address%20match%20event%20occurred%3CBR%20%2F%3Euint8_t%20address%20%3D%20I2C0-%26gt%3BADDR%3B%3C%2FP%3E%0A%3CP%3E%2F%2F%20Check%20the%20LSB%20to%20determine%20read%20(1)%20or%20write%20(0)%3CBR%20%2F%3Eif%20(address%20%26amp%3B%200x01)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%2F%2F%20Read%20command%20(LSB%20is%201)%3CBR%20%2F%3E%2F%2F%20Perform%20actions%20for%20read%20command%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eelse%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%2F%2F%20Write%20command%20(LSB%20is%200)%3CBR%20%2F%3E%2F%2F%20Perform%20actions%20for%20write%20command%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3EHope%20this%20will%20help%20you.%3C%2FP%3E%0A%3CP%3EBR%3C%2FP%3E%0A%3CP%3EHang%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E