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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

663件の閲覧回数
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.

ラベル(1)
0 件の賞賛
返信
1 返信

444件の閲覧回数
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 件の賞賛
返信