AnsweredAssumed Answered

Activating DAC2

Question asked by stotz.dieter on Mar 26, 2014
Latest reply on Jun 2, 2017 by Bruno VELUT
Hello,

I am working with STM8L151C8 with 48 pins.
To my default DAC1 output on PF0 (which works fine) I want to access to the second DAC output, which I want to have on PB6. The Ref manual says that this is possible by configurating the switches, see Doc ID 15226 Rev 10 page 219/575.

In my code I have the following lines in respect to DAC2:

#define DAC2 PIO_Pin_6 //DAC channel 2


#define PB_DDR_Init GPIO_DDR_RESET_VALUE  // not relevant for DAC2
#define PB_ODR_Init GPIO_ODR_RESET_VALUE  // not relevant for DAC2
#define PB_CR1_Init GPIO_CR1_RESET_VALUE | DAC2
#define PB_CR2_Init GPIO_CR1_RESET_VALUE  //clear all bits
 
 
 
  GPIOB->ODR = PB_ODR_Init;
  GPIOB->DDR = PB_DDR_Init;
  GPIOB->CR1 = PB_CR1_Init;
  GPIOB->CR2 = PB_CR2_Init;


RI->IOSR1 = 0x80;  //should be the right one for PB6


DAC->CH1CR1 = DAC_CR1_RESET_VALUE | DAC_CR1_EN; /* DAC1 enable, Buffer on */
DAC->CH2CR1 = DAC_CR1_RESET_VALUE | DAC_CR1_EN; /* DAC2 enable, Buffer on */


    DAC->CH2RDHRH = (uint8_t) (0);
    DAC->CH2RDHRL = (uint8_t) (0);
//    DAC->DCH2RDHRH = 0;  //DAC2 setting to 0
//    DAC->DCH2RDHRL = 0;  //DAC2 setting to 0

I tried both for the last two lines. The result is always, that at PB6 is a voltage of 3.2 Volts. My program does not reset to a certain value or zero.

What is my fault here?

Thank you in advance.

Dieter

Outcomes