AnsweredAssumed Answered

Problem with the OPAMP integrated in STM32L152RB

Question asked by grossi.marco on Jan 21, 2015
I am using a STM32L DISCOVERY board with the microcontroller STM32L152RB on board. I am trying to use the rail-to-rail integrated OPAMP inside the microcontroller.
I have copied the same code proposed in the example files (see it at the end of the discussion). This should connect PA7 to IN- PA6 to IN+ and PB0 to the OPAMP output.
Then I connected PA7 to a sine-wave signal with 1.5V offset and amplitude 1V, PA6 to a DC signal of 1.5V and monitored PB0 with an oscilloscope. The result for PB0 should be a square-wave signal with the same frequency of the sine-wave signal. However, PB0 is always at 0V. Any idea on how to make the OPAMP work?

#include "stm32l1xx_conf.h"
#include "stm32l1xx.h"
#include "stm32l1xx_rcc.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_opamp.h"
#include "stm32l1xx_comp.h"




void OPAMP_Config(void)
{
  GPIO_InitTypeDef   GPIO_InitStructure;


  /* GPIOA and GPIOB Peripheral clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);


  /* Configure PB0 (OPAMP2 output) in analog mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);


  /* Configure PA6 (OPAMP2 positive input) and PA7 (OPAMP2 negative input) in analog mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);


  /* COMP Peripheral clock enable: COMP and OPAMP share the same Peripheral clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, ENABLE);


  /* Enable OPAMP2 */
  OPAMP_Cmd(OPAMP_Selection_OPAMP2, ENABLE);


  /* Close S4 and S5 swicthes */
  OPAMP_SwitchCmd(OPAMP_OPAMP2Switch4 | OPAMP_OPAMP2Switch5, ENABLE);
}








int main(void)
{
    OPAMP_Config();
  while(1)
  {


  }
}

Outcomes