I2C slave - how to receive a undetermined amount of bytes from the example using the transactional method.

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

I2C slave - how to receive a undetermined amount of bytes from the example using the transactional method.

668 Views
dkh
NXP Employee
NXP Employee

The examples for slave i2c are very simplisted (they simply transfer a set amount of bytes each time).  However, for most i2c applications as well as mine, we do read/write transactions.  The biggest problem I am having is that I don’t know if it will be a read or write transaction until I see how many bytes I receive from the master (for a read, I just get the address, for a write, the data follows).  So, I am not sure how to receive a undetermined amount of bytes from the example using the transactional method.

 

In the call back function, if I say to receive 4 bytes (but sometimes 2 bytes will come because it is a read), I get weird cyclical behavior with every i2c transaction.  I was hoping just to give the max amount of bytes I expect to receive, and then look at the actual bytes transferred on the completion event, but it does not behave as expected.

 

Do you know of an app note that shows a more real-world i2c slave example?

 

My environment:

IAR for ARM: 7.20.5.7624

IAR common components: 7.1.2.3324

Segger Jlink

SDK 2.0

Bare metal

info in this thread is referring to the slave interface.

Labels (1)
0 Kudos
Reply
1 Reply

449 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Dennis,

The transactional APIs in KSDK v2.0 expect a fixed size, not a max size. So the I2C transactional driver might not be suitable for the use case of reading/writing a random number of bytes.

Instead you can refer to the i2c_interrupt example which uses the low level functional APIs. Basically the functional APIs abstract register accesses from the user. You just need to customize the IRQ Handler for the project requirements (i.e. the actual handling of Read/Write operations).

Let us know if you have any doubts or concerns.

Regards!

Jorge Gonzalez

0 Kudos
Reply