Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. void DAC_Init( dac_channels_conf_e channel_conf, uint8_t conv_trig_sel, bool output_buffer_used)
  2. {
  3. // Set the DAC out pins as analog pins
  4. GPIO_Analog_Configure(GPIOA, PIN_4 | PIN_5);
  5.  
  6. switch(channel_conf)
  7. {
  8. case dac_dual_channel_simultanous:
  9. {
  10. DAC->CR &= (uint32_t)0;
  11. // Set the conversion trigger source and enable it
  12. DAC->CR |= ((conv_trig_sel << 3) | DAC_CR_TEN1) | (conv_trig_sel << 19) | DAC_CR_TEN2 ;
  13. // Enable the output buffer (if required) to decrease the output impedance
  14. if(output_buffer_used)
  15. {
  16. DAC->CR |= DAC_CR_BOFF1 | DAC_CR_BOFF2;
  17. }
  18. // Enable the peripheral
  19. DAC->CR |= DAC_CR_EN1 | DAC_CR_EN2;
  20. break;
  21. }
  22. default:
  23. {
  24. DAC->CR &= (uint32_t)(0 << channel_conf);
  25. // Set the conversion trigger source and enable it
  26. DAC->CR |= ((conv_trig_sel << 3) | DAC_CR_TEN1) << channel_conf ;
  27. // Enable the output buffer (if required) to decrease the output impedance
  28. if(output_buffer_used)
  29. {
  30. DAC->CR |= DAC_CR_BOFF1 << channel_conf;
  31. }
  32. // Enable the peripheral
  33. DAC->CR |= DAC_CR_EN1 << channel_conf;
  34. break;
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement