cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RCT6 I2C SLAVE transmitter CAN NOT GENERATE ACK

Liu0155
Associate II

Currently I try use STM32F103RCT to implement I2C slave to communicate with master. When master sent address with write bit , there is no any problem and all data can be transmitted to slave through I2C, but when master try to read, it seems big problem. Slave is stuck and master keeping reset. I use scope to check the waveform find that there is no ACK   

response from slave when receive "Start+address+read". Slave can not generate the event "slave transmitter address matched". I checked the community, many people report that similar error. Could you please give me some help? I attached some code for I2C interrupt handle.

void I2C1_EV_IRQHandler(void)   //i2c interrupt handle 

 switch (I2C_GetLastEvent(I2C1))

 { 

 /* Slave Transmitter ---------------------------------------------------*/  

 case I2C_EVENT_SLAVE_BYTE_TRANSMITTED: 

 I2C1_Mode=I2C1_MODE_DATA_BYTE_RD;

 I2C_SendData(I2C1, I2C1TXBuffer[Tx_Idx++]);

  break; 

 case I2C_EVENT_SLAVE_BYTE_TRANSMITTING:       /* EV3 */   

 /* Transmit I2C1 data */

  

 I2C_SendData(I2C1, I2C1TXBuffer[Tx_Idx++]); 

  break; 

 /* Slave Receiver ------------------------------------------------------*/ 

 case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:   /* EV1 */ 

 GPIO_ResetBits(GPIOA,GPIO_Pin_8);//Turn LED0 on

 I2C1_Mode=I2C1_MODE_SLAVE_ADR_WR;

 break; 

 case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED:

 

I2C_SendData(I2C1, I2C1TXBuffer[Tx_Idx++]); 

 break;

 case I2C_EVENT_SLAVE_BYTE_RECEIVED:        /* EV2 */ 

I2C1_Mode=I2C1_MODE_ADR_BYTE;

  

 /* response EV2 interrrupt */ 

 I2C1RXBuffer[Rx_Idx++] = I2C_ReceiveData(I2C1);

 // printf("I2C1RXBuffer=%d\r\n",I2C1RXBuffer[Rx_Idx]);

  

  break; 

 case I2C_EVENT_SLAVE_STOP_DETECTED:        /* EV4 */

I2C1_Mode=I2C1_MODE_WAITING;

break;

}

}

1 REPLY 1
TDK
Guru

You might have better luck using the HAL library instead of the older SPL. Probably are more examples out there for an i2c slave.

Or use registers directly if you are comfortable with it.

If you feel a post has answered your question, please click "Accept as Solution".