AnsweredAssumed Answered

STM32F4 SPI3 interrupt problem

Question asked by tascioglu.emre.001 on Jul 8, 2014
Latest reply on Jul 9, 2014 by Clive One
Hello;

I am working on stm discovery. My aim is get output from speaker. I did it in main function. but i want to use SPI3 interrupt for send data. My codes in below. The code does not go to interrupt. I put breakpoint but its not work. I couldnt find my fault. Could anybody help me?

Thanks for your answers. 

This is my codec init, its work fine when i send data to codec in main.

void codec_init()
{
     GPIO_InitTypeDef PinInitStruct;
     GPIO_StructInit(&PinInitStruct);




     
     PinInitStruct.GPIO_Pin = CODEC_RESET_PIN;
     PinInitStruct.GPIO_Mode = GPIO_Mode_OUT;
     PinInitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
     PinInitStruct.GPIO_OType = GPIO_OType_PP;
     PinInitStruct.GPIO_Speed = GPIO_Speed_50MHz;


     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB, ENABLE);


     GPIO_Init(GPIOD, &PinInitStruct);


     
     PinInitStruct.GPIO_Mode = GPIO_Mode_AF;
     PinInitStruct.GPIO_OType = GPIO_OType_OD;
     PinInitStruct.GPIO_Pin = I2C_SCL_PIN | I2C_SDA_PIN;
     PinInitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
     PinInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOB, &PinInitStruct);


     GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1);




     RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 | RCC_APB1Periph_SPI3, ENABLE);
     RCC_PLLI2SCmd(ENABLE);




     PinInitStruct.GPIO_OType = GPIO_OType_PP;
     PinInitStruct.GPIO_Pin = I2S3_SCLK_PIN | I2S3_SD_PIN | I2S3_MCLK_PIN;
     GPIO_Init(GPIOC, &PinInitStruct);


     PinInitStruct.GPIO_Pin = I2S3_WS_PIN;
     GPIO_Init(GPIOA, &PinInitStruct);




     GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3);




     //keep Codec off for now
     GPIO_ResetBits(GPIOD, CODEC_RESET_PIN);


     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
     NVIC_InitStructure2.NVIC_IRQChannel = SPI3_IRQn;
     NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStructure2.NVIC_IRQChannelSubPriority = 0;
     NVIC_InitStructure2.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure2);
     // configure I2S port
     SPI_I2S_DeInit(CODEC_I2S);
     I2S_InitType.I2S_AudioFreq = I2S_AudioFreq_16k;
     I2S_InitType.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
     I2S_InitType.I2S_DataFormat = I2S_DataFormat_16b;
     I2S_InitType.I2S_Mode = I2S_Mode_MasterTx;
     I2S_InitType.I2S_Standard = I2S_Standard_Phillips;
     I2S_InitType.I2S_CPOL = I2S_CPOL_Low;


     I2S_Init(CODEC_I2S, &I2S_InitType);
     
        I2S_FullDuplexConfig(I2S3ext, &I2S_InitType);
  
     // configure I2C port
     I2C_DeInit(CODEC_I2C);
     I2C_InitType.I2C_ClockSpeed = 100000;
     I2C_InitType.I2C_Mode = I2C_Mode_I2C;
     I2C_InitType.I2C_OwnAddress1 = CORE_I2C_ADDRESS;
     I2C_InitType.I2C_Ack = I2C_Ack_Enable;
     I2C_InitType.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
     I2C_InitType.I2C_DutyCycle = I2C_DutyCycle_2;


     I2C_Cmd(CODEC_I2C, ENABLE);
     I2C_Init(CODEC_I2C, &I2C_InitType);
  SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE);


}

void I2S3_IRQHANDLER(void) {
if(SPI_GetITStatus(SPI3, SPI_I2S_IT_TXE) != RESET)
{SPI_I2S_SendData(SPI3,Buffer[counter]);} 
}

Outcomes