NXP S32K148 - I2C Sniffer

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

NXP S32K148 - I2C Sniffer

跳至解决方案
2,892 次查看
adan_pantoja
Contributor I

Hello all,

Background

  • Board: S32K148
  • SDK: v4.0.3
  • OS: freeRTOS

Problem

I am currently working on a project which requires me to monitor an i2c bus and record all information passing between the master and slave. Initially I thought you would be able to configure the lpi2c as a slave, give it an arbitrary address, and configure the callback to execute whenever anything was detected on the lines. The issue is that it appears the callback routine only triggers whenever an i2c frame is directed at my sniffer node (same slave address). Otherwise, the program never enters the callback even though traffic is seen on the bus. 

Because of the previous issue, I then resorted to use a regular GPIO to trigger on SCL and decode the data that way. I then ran into  issue with this method:

  1. I do not know how to to let the software know when all bytes have been received because it is a regular interrupt (No TX/RX complete flags).
  2. Because I have to process interrupts back-to-back I ran into issues writing some logic within the ISR handler to notify the program when the last byte was received. (I tried adding some logic, but this causes the program to miss some bits).

I tried using a freeRTOS timer that will continuously reset every time it receives a bit, therefore whenever the timer expires, I can set a flag to notify my software. Unfortunately, this causes some latency in the interrupts and I'll miss bits.  

So my question: Is there a way to configure lpi2c to sniff the bus and store all data in a buffer (regardless of node address)? If lpi2c cannot be used, what method do you guys recommend for creating the sniffer?

 

I appreciate the help!

Thank you.

0 项奖励
回复
1 解答
2,835 次查看
adan_pantoja
Contributor I

Thank you for your reply.

I was able to create the sniffer using the GPIO method. I configured the SCL and SDA gpio pins to react on interrupts; SCL reacting on rising edge and SDA reacting on either edge. I also set the SCL interrupt to be a higher priority than the SDA. Doing it this was allowed me to receive and decode the entire message using the start and stop condition of the I2C frame.

 

Hopefully this helps anyone else trying to create a sniffer.

在原帖中查看解决方案

0 项奖励
回复
2 回复数
2,836 次查看
adan_pantoja
Contributor I

Thank you for your reply.

I was able to create the sniffer using the GPIO method. I configured the SCL and SDA gpio pins to react on interrupts; SCL reacting on rising edge and SDA reacting on either edge. I also set the SCL interrupt to be a higher priority than the SDA. Doing it this was allowed me to receive and decode the entire message using the start and stop condition of the I2C frame.

 

Hopefully this helps anyone else trying to create a sniffer.

0 项奖励
回复
2,874 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

the LPI2C slave can be configured to match a range of addresses in either 7-bit or 10-bit addressing modes, so it would be able to react on all addresses if configured in that way. But not sure how you get data when slave is going to transmit data.
I think you will need to set GPIO's in input mode, either with polling or interrupts on transition, and interpret the bus events internally. Maybe you will find some hints/codes on the web for this SW I2C sniffer.

BR, Petr

0 项奖励
回复