2024-05-02 9:48 AM
I am looking at the definition ST gives for each of the Xfer options, but so far none of them really are making sense to me. First off, what is Sequential usage vs non-sequential usage and how does this apply for the following:
I2C_FIRST_AND_LAST_FRAME
I2C_FIRST_FRAME
I2C_FIRST_AND_NEXT_FRAME
I2C_NEXT_FRAME
I2C_LAST_FRAME
I2C_LAST_FRAME_NO_STOP
I2C_OTHER_FRAME
Solved! Go to Solution.
2024-05-30 6:58 AM
Hello @tomm5771
In the context of I2C communication, the HAL library defines several transfer options to manage the sequence of frames during an I2C transaction. These options are used to indicate how the I2C controller should handle each part of the communication process, particularly when dealing with multi-frame communications.
Let's explain the concepts of sequential and non-sequential usage:
Now, let's explain each of the Xfer options:
This option is used when the transaction consists of a single frame. It indicates that this frame is both the first and the last frame of the transaction. The I2C controller will generate a start condition at the beginning and a stop condition at the end of this frame.
This option is used to indicate the start of a multi-frame transaction. The I2C controller will generate a start condition and will expect more frames to follow. No stop condition is generated after this frame, allowing the transaction to continue with the next frame.
This option is similar to I2C_FIRST_FRAME but is specifically used when you know that there will be at least one more frame following the first frame. It prepares the I2C controller for a continued transaction without generating a stop condition.
This option is used for frames that are neither the first nor the last in a multi-frame transaction. It indicates that the frame is part of a sequence and that there will be subsequent frames. No start or stop conditions are generated, as the transaction is already in progress.
This option is used for the final frame in a multi-frame transaction. It indicates that no more frames will follow, and the I2C controller will generate a stop condition after this frame to end the transaction.
This option is similar to I2C_LAST_FRAME but does not generate a stop condition at the end of the frame. This can be used when the master plans to send a repeated start condition to begin a new transaction immediately after the current one.
When implementing I2C communication, it's important to choose the correct Xfer option based on the sequence and structure of your data transfer. This ensures that the I2C controller handles the start and stop conditions appropriately and that the communication with the I2C slave device is successful.
2024-05-30 6:58 AM
Hello @tomm5771
In the context of I2C communication, the HAL library defines several transfer options to manage the sequence of frames during an I2C transaction. These options are used to indicate how the I2C controller should handle each part of the communication process, particularly when dealing with multi-frame communications.
Let's explain the concepts of sequential and non-sequential usage:
Now, let's explain each of the Xfer options:
This option is used when the transaction consists of a single frame. It indicates that this frame is both the first and the last frame of the transaction. The I2C controller will generate a start condition at the beginning and a stop condition at the end of this frame.
This option is used to indicate the start of a multi-frame transaction. The I2C controller will generate a start condition and will expect more frames to follow. No stop condition is generated after this frame, allowing the transaction to continue with the next frame.
This option is similar to I2C_FIRST_FRAME but is specifically used when you know that there will be at least one more frame following the first frame. It prepares the I2C controller for a continued transaction without generating a stop condition.
This option is used for frames that are neither the first nor the last in a multi-frame transaction. It indicates that the frame is part of a sequence and that there will be subsequent frames. No start or stop conditions are generated, as the transaction is already in progress.
This option is used for the final frame in a multi-frame transaction. It indicates that no more frames will follow, and the I2C controller will generate a stop condition after this frame to end the transaction.
This option is similar to I2C_LAST_FRAME but does not generate a stop condition at the end of the frame. This can be used when the master plans to send a repeated start condition to begin a new transaction immediately after the current one.
When implementing I2C communication, it's important to choose the correct Xfer option based on the sequence and structure of your data transfer. This ensures that the I2C controller handles the start and stop conditions appropriately and that the communication with the I2C slave device is successful.
2025-04-13 2:38 PM - edited 2025-04-13 3:56 PM
Hi @Saket_Om
Can you also provide and explanation of these XferOptions?
1- I2C_OTHER_FRAME
2- I2C_OTHER_AND_LAST_FRAME
I can't seem to get this to work properly:
ret = HAL_I2C_Master_Seq_Transmit_IT(&hi2c1, XO2FPGA_ADDR, cmd, 4, I2C_FIRST_AND_NEXT_FRAME);
while (transmission_complete_flag == 0) {} ;
ret = HAL_I2C_Master_Seq_Receive_IT(&hi2c1, XO2FPGA_ADDR, data, 4, I2C_OTHER_AND_LAST_FRAME);
while (reception_complete_flag == 0) {};
On the scope, I see:
line 1: start condition, addr sent, 4 bytes sent [addr=0x80, cmd=0xE0 0x00 0x00 0x00]
line 2: got interrupt and transmission_complete_flag set (seems to get interrupt after first byte sent instead of end of frame)
line 3: Restart seen on scope, but no other data is sent. I was expecting:
Restart, addr, 4 bytes recv, stop
trying to accomplish this:
thanks
2025-04-13 5:48 PM
ok, I finally figured it out.... it's not that obvious and I couldn't find any documentation from ST...
Summary, to do a transaction like this:
use code:
ret = HAL_I2C_Master_Seq_Transmit_IT(&hi2c1, XO2FPGA_ADDR, &cmd[0], 3, I2C_FIRST_AND_NEXT_FRAME);
while (transmission_complete_flag == 0) {} ; transmission_complete_flag = 0;
ret = HAL_I2C_Master_Seq_Transmit_IT(&hi2c1, XO2FPGA_ADDR, &cmd[3], 1, I2C_LAST_FRAME_NO_STOP);
while (transmission_complete_flag == 0) {} ; transmission_complete_flag = 0;
ret = HAL_I2C_Master_Seq_Receive_IT(&hi2c1, XO2FPGA_ADDR, data, 4, I2C_OTHER_AND_LAST_FRAME);
while (reception_complete_flag == 0) {}; reception_complete_flag = 0;