Hi,
I’ve been working on I2C communication between a PSOC 5LP (master) and multiple PSOC 4’s (slaves). This is being done with a Cy8CKIT-059 and multiple Cy8CKIT-049-42xx boards. The goal is to be able to add a slave device to the bus, in a default configuration with address 0x08, and have the master assign it a new address and maintain a list of all currently used slave addresses. The slave stores its address in flash (Emulated EEPROM) so at power up the configuration remains unchanged. For now, the part about having the master store a list of addresses has been set aside and I’m just sending commands through USBUART via a terminal.
Most of this project is functioning correctly, but I’m running into a few hiccups that really come down to error checking. There are also some parts of the code that aren’t exactly elegant, but thus far my goal has been to just get things working, so please excuse them. I have attached a zip with the main.c and main.h for both the master and slave. My questions are:
1. I am using the I2CMasterWriteBuf and I2CMasterReadBuf API functions and they are working well. My problem is that these API functions are returning “SCB_I2C_MSTR_NO_ERROR” when they try to talk to a slave address that does not exist. I am clearly not understanding how the return value of the functions is created and would like to be able to find out if a slave is not on the bus and generate an error.
2. The second concern is regarding sending a save device a command to change its address. I am currently using a simple block check to validate packets, which is working as expected. I would like to find a way to generate some kind of acknowledgement from a slave saying that the incoming packet is valid before executing its address change. This way the master knows the packet was received correctly and can update its slave address array accordingly.
As of now if the block check isn’t correct the slave will not attempt to update its address, but the master has no way of knowing that this did not happen. The only way I can do this right now is to attempt to read from the new slave address and see if the correct status value is returned, indicating a successful address change, though if the address isn’t there I run into the previous problem. This can be worked around by checking that the status in the returned packet is correct, but it feels a bit like going around my elbow to get to my rear and, frankly, I don’t really like it.
I’m currently using the MasterWriteBuf and MasterReadBuf functions with the mode set to “MODE_COMPLETE_XFER” which I have a hunch is part of the problem. I feel like I need to use the “MODE_NO_STOP” mode, but I don’t understand how this works and can’t seem to get things working with it.
I’m new to Cypress devices as well as I2C. Any help with understanding where my logic is incorrect or guidance to a solution would be greatly appreciated. If anything isn’t clear I’ll be happy to try and resolve any ambiguity.
Thanks,
Matthew