Problem using Slave to transmit I2C Interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-21 5:59 AM
Hi,
In my project, I communicate with STM slave I2C. I can receive data via I2C but I cannot send data. As you can see in the photo below, the packetData is filling up, but when you send it, it only sends 0x00. what is the problem? what can I do?
- Labels:
-
I2C
-
Interrupt
-
STM32F0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-12-21 6:24 AM
Probably a code bug. Perhaps your data goes out of scope immediately. Perhaps you aren't using HAL_I2C_Slave_Seq_Transmit_IT correctly.
Does HAL_I2C_Slave_Transmit work as expected?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-01 10:58 PM
HAL_I2C_Slave_Transmit don't work as expected. @TDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-01 11:04 PM
I am receiving data with I2C Slave Interrupt and I am having problem while sending data and I am using HAL_I2C_Slave_Transmit while sending data. Below are my interrupt codes. Could the interrupt setup have caused an error?
/* USER CODE BEGIN 1 */
void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
{
first = SET;
if(i2c_interrupt_enable)
{
HAL_I2C_EnableListen_IT(hi2c); // slave is ready again
}
}
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode)
{
if( TransferDirection==I2C_DIRECTION_TRANSMIT ) {
if( first ) {
HAL_I2C_Slave_Seq_Receive_IT(hi2c, &offset, 1, I2C_NEXT_FRAME);
} else {
HAL_I2C_Slave_Seq_Receive_IT(hi2c, &ram[offset], 1, I2C_NEXT_FRAME);
}
} else {
HAL_I2C_Slave_Seq_Transmit_IT(hi2c, &ram[offset], 1, I2C_NEXT_FRAME);
}
}
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)
{
if(first) {
first = RESET;
} else {
offset++;
}
I2C_NFCReaderCallbackPacketCapture(&hi2c2,&ram[offset],esp32PacketBuffer);
callback_counter++;
}
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
offset++;
HAL_I2C_Slave_Seq_Transmit_IT(hi2c, &ram[offset], 1, I2C_NEXT_FRAME);
}
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
{
if( HAL_I2C_GetError(hi2c)==HAL_I2C_ERROR_AF ) {
offset--; // transaction terminated by master
} else {
}
}
/* USER CODE END 1 */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-02 6:40 AM
Your code there looks quite different than your code in the original post.
You can see an example of how these functions are used here:
Not sure you've included enough code to diagnose. The "offset" variable is never initialized, for instance.
