Stm32f103C8 External Dac

Working libraries, libraries being ported and related hardware
stm32user
Posts: 13
Joined: Wed Nov 25, 2015 3:30 pm

Stm32f103C8 External Dac

Post by stm32user » Mon Jan 15, 2018 12:54 pm

Hello there

I want to use an external DAC in Stm32f103c8.

How can I get a value of 0-255 as 8 logic output.

thax :roll:

User avatar
Pito
Posts: 1734
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Stm32f103C8 External Dac

Post by Pito » Mon Jan 15, 2018 1:02 pm

Which external DAC, give us the link..
Pukao Hats Cleaning Services Ltd.

stm32user
Posts: 13
Joined: Wed Nov 25, 2015 3:30 pm

Re: Stm32f103C8 External Dac

Post by stm32user » Mon Jan 15, 2018 1:11 pm

Pito wrote:
Mon Jan 15, 2018 1:02 pm
Which external DAC, give us the link..
I do not have any schematics.

For example PA0 PA1 PA2 PA3 PA4 PA5 PA6 I can get 8 outputs with for 0-255 data.

or if the outputs are different

PA0, PA1, PB2, PB5 etc.

User avatar
Pito
Posts: 1734
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Stm32f103C8 External Dac

Post by Pito » Mon Jan 15, 2018 1:52 pm

With 103C8 you may use

Code: Select all

analogWrite(pin, value);  // value 0 - 255

analogWrite(PA7, 189);

or

pwmWrite(pin value); // value 0 - 65535 
Works on specific pins.

You need a low-pass filter to get an analog value, however.

There is none hw DAC in 103C8.
Pukao Hats Cleaning Services Ltd.

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: Stm32f103C8 External Dac

Post by dannyf » Mon Jan 15, 2018 1:58 pm

How can I get a value of 0-255 as 8 logic output.
generally you write a piece of code, as per the datasheet of your external DAC, to communicate with it.

that works 100% of the time with 100% of the devices, DAC or not.

User avatar
Pito
Posts: 1734
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Stm32f103C8 External Dac

Post by Pito » Mon Jan 15, 2018 2:06 pm

Be more specific, what external DAC you want to use (if any)?
There are R2R DACs, 1-2-4-8..R DACs, I2C DACs, SPI DACs, parallel DACs, PWM DACs, etc..
Pukao Hats Cleaning Services Ltd.

stm32user
Posts: 13
Joined: Wed Nov 25, 2015 3:30 pm

Re: Stm32f103C8 External Dac

Post by stm32user » Mon Jan 15, 2018 2:14 pm

Image


can we do it like the picture?

User avatar
Pito
Posts: 1734
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Stm32f103C8 External Dac

Post by Pito » Mon Jan 15, 2018 2:16 pm

That is the R2R DAC.
Yes you can do it, sure. You may wire it to a port, ie. PortA or PortB, PA0-PA7 or PB0-PB7, and then send the DAC value to the PortA or PortB in a single write.
Mind the stm32 is a 3.3Volt device, thus the R2R output will be 0..3.28V max.
Pukao Hats Cleaning Services Ltd.

stm32user
Posts: 13
Joined: Wed Nov 25, 2015 3:30 pm

Re: Stm32f103C8 External Dac

Post by stm32user » Mon Jan 15, 2018 2:34 pm

Thanks for the answer, if I want to use different pins?

PA0, PA1, PA2, PB12, PB13, PB14, PA3, etc.

There is a method

User avatar
Pito
Posts: 1734
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Stm32f103C8 External Dac

Post by Pito » Mon Jan 15, 2018 2:48 pm

You may set the bits individually. First set the individual pins to outputs, then write the DACvalue:

Code: Select all

pinMode(PA0, OUTPUT);
..
pinMode(PB12, OUTPUT);
..
// write the DACvalue 0-255, 8bit
digitalWrite(PA4, (DACvalue & 0x80));  // the highest DACvalue bit7
digitalWrite(PA3, (DACvalue & 0x40));
digitalWrite(PB14, (DACvalue & 0x20));
digitalWrite(PB13, (DACvalue & 0x10));
digitalWrite(PB12, (DACvalue & 0x08));
digitalWrite(PA2, (DACvalue & 0x04));
digitalWrite(PA1, (DACvalue & 0x02));
digitalWrite(PA0, (DACvalue & 0x01));  // the lowest DACvalue bit0
..
Last edited by Pito on Mon Jan 15, 2018 6:02 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

Post Reply