cancel
Showing results for 
Search instead for 
Did you mean: 

Activating DAC2

d23
Associate II
Posted on March 26, 2014 at 12:25

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
1 REPLY 1
Bruno VELUT
Associate
Posted on June 02, 2017 at 10:51

Hello Dieter

I have the same problem with the DAC2 on the same micro processor.

Do you have fixed your problem ? I do not understand why much questions are in suspend, the DAC 2 is a real problem whereas the DAC 1 is quite easy to configure.

So in my enquiry, in order to activate the routing of DAC2 to PB4, I set the AnalogueSwitch_4 and RI_IO_SWITCH 15

(I work with the Cosmic C compiler) if you have any information, it will be great.

Regards

Bruno VELUT