i2c gestionnaire d'interruption stm32
J'ai quelques problèmes avec I2C2 interruptions, j'ai activé l'interrompre, mais le gestionnaire d'interruption ne s'exécute jamais.
Ici est la i2c2 initialisation:
void i2c2InitSlave(void)
{
I2C_DeInit(I2C2);
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
/*I2C2 Peripheral clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
/* Enable GPIO clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE);
//I2C2 SCL and SDA Pin configuration
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource4, GPIO_AF_I2C2);
GPIO_PinAFConfig(GPIOH, GPIO_PinSource5, GPIO_AF_I2C2);
/* Initialize I2C peripheral */
/* I2C Init */
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = SLAVE_ADDRESS;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
/* Enable I2C2 */
I2C_Cmd(I2C2, ENABLE);
I2C_Init(I2C2, &I2C_InitStructure);
Tx_Index = 0;
Rx_Index = 0;
}
Ici est l'interruption de configuration:
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the I2C event priority */
NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
Et ici, c'est le gestionnaire d'interruption:
/**
* @brief Interrupt handler for i2c interface.
* @param None
* @retval None
*/
void I2C2_EV_IRQHandler(void)
{
switch(I2C_GetLastEvent(I2C2))
{
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED :
break;
case I2C_EVENT_SLAVE_BYTE_RECEIVED:
i2c_read_packet[Rx_Index] = I2C_ReceiveData(I2C2); //Store the packet in i2c_read_packet.
Rx_Index++;
break;
case I2C_EVENT_SLAVE_STOP_DETECTED :
Rx_Index = 0;
packets_recv_i2c++;
i2cProcessPacket();
break;
case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED:
I2C_SendData(I2C2, i2c_packet_to_send[0]);
Tx_Index++;
break;
case I2C_EVENT_SLAVE_BYTE_TRANSMITTED:
I2C_SendData(I2C2, i2c_packet_to_send[Tx_Index]);
Tx_Index++;
break;
case I2C_EVENT_SLAVE_ACK_FAILURE:
Tx_Index = 0;
packets_sent_i2c++;
break;
default:
break;
}
}
Une idée?
BR,
Edgar.
OriginalL'auteur edgar.epi | 2013-08-29
Vous devez vous connecter pour publier un commentaire.
Okay, si vous avez inscrit votre interruption de configuration et un maître-chien, mais en ce qui concerne votre I2C initialisation en général?
Vous ne serez pas générer tout les interruptions si l'I2C n'est pas initialisé.
Vous devez reconnaître ce bloc (ou certains analogique):
Où I2C_Config peut être définie comme suit:
Et la I2C_InitTypeDef est définie comme suit:
Remarque: l'Utilisation d'un ensemble de
#define
'(peut-être dans un en-tête) lors de la configuration rend la vie plus facile. Par exemple:...Et PLUS important encore, jetez un oeil à "stm32f4xx_i2c.c" disponible ici. Lisez la section "Comment Utiliser Ce Pilote" commentaire au dessus.
Si vous avez déjà tout cela dans votre projet, post afin que nous puissions voir ce que vous avez fait là.
J'ai déjà eu l'initilization code. J'ai changé de i2c3 à i2c2 mais ne fonctionne toujours pas.
Vous devez appeler I2C_ITConfig(I2C2, ACTIVER). Je vois que tu as édité ton post pour y inclure votre code d'initialisation, mais ne voient pas cette liste. Lui donner un essai.
Je vais l'essayer dès que possible. Je vais vous laisser savoir. Merci!
OriginalL'auteur bunkerdive