2023-12-21 05: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?
2023-12-21 06: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?
2024-01-01 10:58 PM
HAL_I2C_Slave_Transmit don't work as expected. @TDK
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 */
2024-01-02 06: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.