2023-11-18 06:43 AM - edited 2023-11-18 06:49 AM
Hello everyone! I have been complaining about this for 1 week. I can't make "HAL_I2C_Slave_Seq_Transmit_IT" send data to the master, but Slave to master ACK works fine, does anyone have any advice to give me that can guide me a little? I am using the STM32F030. in another way i need the slave to respond to many ADDRESS for this i configure the mask to pass any address possible. Clock STRETCH or not dont affect this trouble.
The interruptions in "NVIC settings" are activated (i2C global interrupt), the frequency is the maximum possible (64Mhz) and the master speed is 20Khz, I have also tried with 100,400,1000 Khz and nothing worked, the Slave ACK perfectly in any frequency. in another way if i use "HAL_I2C_Slave_Seq_Receive_IT" slave receives data perfectly. in another way when i try to transmit data to master, im getting in
"HAL_I2C_GetError(hi2c);"
the error code 0x0A.... what this mean?
My code:
#define RxSIZE 100
uint8_t RxData[RxSIZE];
uint8_t TxData[RxSIZE];
uint8_t errorcode;
int countError = 0;
void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c){
HAL_I2C_EnableListen_IT(hi2c);
}
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode){
if(TransferDirection == I2C_DIRECTION_TRANSMIT){
}else{
HAL_I2C_Slave_Seq_Transmit_IT(hi2c, TxData, 6, I2C_FIRST_AND_NEXT_FRAME);
}
}
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c){ // this function never called!!!!
}
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c){} //Not used But work if i Send data Master->Slave
/*
#define HAL_I2C_ERROR_NONE (0x00000000U) !< No error
#define HAL_I2C_ERROR_BERR (0x00000001U) !< BERR error
#define HAL_I2C_ERROR_ARLO (0x00000002U) !< ARLO error
#define HAL_I2C_ERROR_AF (0x00000004U) !< ACKF error
#define HAL_I2C_ERROR_OVR (0x00000008U) !< OVR error
#define HAL_I2C_ERROR_DMA (0x00000010U) !< DMA transfer error
#define HAL_I2C_ERROR_TIMEOUT (0x00000020U) !< Timeout error
#define HAL_I2C_ERROR_SIZE (0x00000040U) !< Size Management error
#define HAL_I2C_ERROR_DMA_PARAM (0x00000080U) !< DMA Parameter Error
*/
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){
countError++;
errorcode = HAL_I2C_GetError(hi2c); // this responds -> 0x0A ????
HAL_I2C_EnableListen_IT(hi2c);
}
///////////////////// main //////////////////////////////////
/* USER CODE BEGIN 2 */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
for(uint16_t i=0;i<100;i++)TxData[i] = i;
while(HAL_I2C_GetState(&hi2c2)!=HAL_I2C_STATE_READY);
if(HAL_I2C_EnableListen_IT(&hi2c2)!= HAL_OK){
countError++;
}
while (1);
Solved! Go to Solution.
2023-11-19 07:13 AM
Hi everyone and thanks for taking your time in help me. I decide to search and make in LOW-Level implementation in Blocking mode, this Works perfect for me.
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode){
I2C2->TXDR = 1;
while(!READ_BIT(I2C2->ISR, TXIS));
I2C2->TXDR = 2;
while(!READ_BIT(I2C2->ISR, TXIS));
I2C2->TXDR = 3;
}
PD.: Any HAL function return the data to the master included function in Blocked / non bloqued / DMA mode
2023-11-18 07:13 AM
I used I2C_NEXT_FRAME, not I2C_FIRST_AND_NEXT_FRAME. The UM1940 - Rev 3 user manual says something about flag usage. I also used sending single bytes only (not 6) to keep fine grained control over what's happening on the bus. But is may (shall?) work for 6 too.
hth
KnarfB
2023-11-18 07:20 AM
the same with "I2C_NEXT_FRAME" and 1 or 6 bytes of response.... :(
2023-11-18 07:36 AM
Why you use HAL_I2C_Slave_Seq_Transmit_IT, seems by comment in headers is designed for SMBUS and no real example founded in pack.
2023-11-18 08:14 AM
Mmmm but in this case for me its the same as the SMBUS... i dont undertand your point.
2023-11-19 02:32 AM
Yes right, but i after deep search found only one example in C:\Users\mmmmm\STM32Cube\Repository\STM32Cube_FW_F0_V1.11.4\Projects\STM32F072RB-Nucleo\Examples\I2C\I2C_TwoBoards_RestartComIT\
and to this time never use this func with slave. But seems next relevant info here I2C Slave Driver Race Condition · Issue #76 · STMicroelectronics/STM32CubeF4 · GitHub
2023-11-19 06:04 AM
Don't have (your) hardware at hand, but my code used to work flawlessly: https://gitlab.com/stm32mcu/i2c_master_and_servant
hth
KnarfB
2023-11-19 07:13 AM
Hi everyone and thanks for taking your time in help me. I decide to search and make in LOW-Level implementation in Blocking mode, this Works perfect for me.
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode){
I2C2->TXDR = 1;
while(!READ_BIT(I2C2->ISR, TXIS));
I2C2->TXDR = 2;
while(!READ_BIT(I2C2->ISR, TXIS));
I2C2->TXDR = 3;
}
PD.: Any HAL function return the data to the master included function in Blocked / non bloqued / DMA mode