Skip to content

Updated i2c pipe data transfer #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2022
Merged

Updated i2c pipe data transfer #17

merged 5 commits into from
Aug 9, 2022

Conversation

cnbecks
Copy link
Collaborator

@cnbecks cnbecks commented Aug 2, 2022

Altered the i2c_read_long and i2c_receive methods in order to read in sensor data through the FIFO pipe without also reading it in through the wire. Pipe data transfer now works and is more time efficient. Summary of the changes:

  • i2c_read_long: added data_transfer parameter that is passed along to i2c_receive (default value is 'wire')
  • i2c_receive: replaced old code with a short sleep to give the pipe time to fill

@cnbecks cnbecks requested review from lucask07 and Ajstros August 2, 2022 19:52
Copy link
Owner

@Ajstros Ajstros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what functionality these changes add. If you use the 'pipe' option, it looks like you never receive data from these functions, it just goes to a time.sleep and ends. @cnbecks Could you provide some context as to how these functions are being used that requires the time.sleep with no data?

if data_transfer.lower() == 'pipe':
# this does not take care of the FIFO reset
# wait so next data is ready, then continue
time.sleep(0.01)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that if data_transfer is set to 'pipe', then no data is returned from this function. Why is that?

Copy link
Collaborator Author

@cnbecks cnbecks Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ajstros sorry for the confusion! Currently there are separate methods that are being used to read out and clear the pipe (read_i2c_pipe and reset_i2c_fifo, which are both located in the TMF8801_sandbox.py file), the reason for the change in I2CController.py is to avoid reading data through the wire in the process of reading it through the pipe, which is why there is only a time.sleep call and nothing else. The time.sleep is included because without it the pipe is occasionally read before being filled, creating incomplete or corrupted histograms.

Here are the methods I mentioned if you want to take a look! And definitely let me know if you have more questions.

def read_i2c_pipe(tof_dev, data_len=256):
    return tof_dev.fpga.read_pipe_out(tof_dev.endpoints['PIPE_OUT'].address, 
                                      data_len)

def reset_i2c_fifo(tof_dev):
    tof_dev.fpga.xem.ActivateTriggerIn(
            tof_dev.endpoints['FIFO_RESET'].address, tof_dev.endpoints['FIFO_RESET'].bit_index_low)  # High and low bit indexes are the same for the trigger because it is 1 bit wide

Copy link
Owner

@Ajstros Ajstros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last couple changes I committed add the FIFO reset and PIPE read functionality into i2c_receive so the function works on its own and remains general enough that future peripherals could also use this I2C pipe data functionality.

Copy link
Owner

@Ajstros Ajstros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cnbecks I almost forgot but the added data_transfer parameter in i2c_receive and i2c_read_long should be added to each of their docstrings as well. Something like this for example for i2c_receive.

def i2c_receive(self, data_length, data_transfer='wire'):
    """Take in data from the SCL and SDA lines.
    
    Parameters
    ----------
    data_length : int
        Number of bytes expected to receive.
    data_transfer : str
        The form of the data transfer. Either 'wire' and 'pipe'. Defaults to 'wire'.

    Returns
    -------
    data or buf, e : list or bytearray, int
        The data or a bytearray and error code, depending on whether data_transfer was 'wire' or 'pipe'.
    """

Could you copy this in and add something similar for data_transfer to the i2c_read_long docstring?

@Ajstros
Copy link
Owner

Ajstros commented Aug 8, 2022

@cnbecks I think we can merge this now. I believe everything is set up so you should be able to merge (please use the "Squash and merge" option for this) so I'll let you do it.

@cnbecks cnbecks merged commit ee3e759 into main Aug 9, 2022
@cnbecks
Copy link
Collaborator Author

cnbecks commented Aug 9, 2022

@Ajstros hopefully that worked properly. Let me know if something went awry!

@Ajstros
Copy link
Owner

Ajstros commented Aug 9, 2022

@cnbecks Looks good, thanks!

@Ajstros Ajstros deleted the i2c_edits branch August 9, 2022 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants