0

I am trying to get two way communication going between a raspberry pi and a microchip, where the raspberry pi is the slave. My current solution is working fine, except for the fact that the raspberry pi seems to struggle sending multiple bytes at a time.

My current setup has the raspberry pi set a GPIO pin high on the microntroller, telling it to start a transaction. The microcontroller then write request and basically asks "What's up?" by sending a specific byte over the I2C bus and then a read request. In response to this, the raspberry pi sends a single instruction byte, basically telling the chip what to do so it knows how many bytes to read the next time and what action to take. In almost all cases the chipp responds with some sort of write request to the raspberry pi.

This works, and all is fine and good, but the issue is that sometimes commands get repeated. For instance, I tell the raspberry pi to send it command 0. Command 0 is successfully sent. Next I ask it to send command 3. Command 0 is sent instead, and then if I ask it to send command 0 again it will send command 3. I have a large wait between the commands being sent as well to prevent nonsense related to the stuff not being removed from the FIFO thing fast enough inside of the raspberry pi.

#This function is called every time i2c is received
def i2c(id, tick):
    global pi
    pi.write(GPIO, 0)
    s, b, d = pi.bsc_i2c(I2C_ADDR)
    if(b > 0):
            s, b, d = pi.bsc_i2c(I2C_ADDR, data=doI2CResponse(d, d[0]))
    return 1

doI2C_Respond just returns an array dependent on what the microcontroller said. In the case of the microcontroller asking "What's up" it just returns an array with a single element that is the command. Do I have to manually do error checking or is it a code issue? Additionally, is there a way to flush the FIFO pipe?

Mrmola
  • 1
  • 1

0 Answers0