I2C slave on PSoC 5LP

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
FeSa_2756246
Level 1
Level 1

Hello everybody,

I'm trying to realize a bridge I2C - SPI with a board that carries a PSoC 5LP. The board receives I2C packets from another board with Linux inside (commands like i2cset and i2cget) and converts them to SPI format towards a board with a camera sensor. The first board is a I2C master and the sensor is an SPI slave, so the PSoC implements an I2C slave and an SPI master.

The problem I am facing with is that I don't understand how to correctly detect, in the PSoC, that I have received a get or a a set instruction. It doesn't seem to exist any interrupt callback that signal that event; there are some flags, though, that are set in a odd way and, it seems, not constant sequence. Due to this behaviour and because I check these status flags to detect the sets and gets, sometimes after a get instruction (correctly detected) it also catch a get instruction, thus performing an undesidered write on SPI.

The pseudo code is the following:

while(1)

{

  if(write status flags are set)

  do spi write

  else if(read status flags are set)

  {

  do spi read

  copy data to i2c buffer

  }

}

Does anyone know how to correctly detect the i2c packets? I'm using PSoC Creator 4.1 as IDE.

Thank you

0 Likes
2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You may read the I2C slave status to poll for a complete transfer and any errors occured. Then by querying the buffer size API you can see how many bytes have been received or need transmission.

Bob

Thank you very much Bob, I have found a workaround though not finding, I think, how that software object (I2C Slave) is meant to be used.

I alredy performed a poll checking the status flags but there was the problem I specified in my previous post.

The workaround is to add a futher check to detect the incoming write command using the buffer size API you mentioned (thank you!).

There are two functions, one for the read buffer and one for the write buffer. Currently I check that SlaveGetReadBufSize returns zero because if it receives something but the read buffer is empty it must have been a write command.

0 Likes