Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
0a58b8dd8This file is pinned to the selected release. Download the original to open it in your design tool.
diff --git a/frames/drivers/dac.cc b/frames/drivers/dac.cc
index 1b45bbc..ab0c458 100755
--- a/frames/drivers/dac.cc
+++ b/frames/drivers/dac.cc
@@ -31,12 +31,19 @@
namespace frames {
void Dac::Init() {
- // Initialize SS pin.
+ // Initialize SS pins.
GPIO_InitTypeDef gpio_init;
- gpio_init.GPIO_Pin = kPinSS;
+ gpio_init.GPIO_Pin = kPinDAC1_SS | kPinDAC2_SS;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &gpio_init);
+ GPIO_Init(GPIOA, &gpio_init);
+
+ // Initialize and set LDAC pin.
+ gpio_init.GPIO_Pin = kPinLDAC;
+ gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
+ gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
+ GPIO_Init(GPIOA, &gpio_init);
+ GPIOA->BRR = kPinLDAC;
// Initialize MOSI and SCK pins.
gpio_init.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
diff --git a/frames/drivers/dac.h b/frames/drivers/dac.h
index 9679bb3..21ca592 100755
--- a/frames/drivers/dac.h
+++ b/frames/drivers/dac.h
@@ -37,7 +37,9 @@
namespace frames {
-const uint16_t kPinSS = GPIO_Pin_12;
+const uint16_t kPinLDAC = GPIO_Pin_8;
+const uint16_t kPinDAC1_SS = GPIO_Pin_12;
+const uint16_t kPinDAC2_SS = GPIO_Pin_11;
class Dac {
public:
@@ -49,9 +51,10 @@ class Dac {
data_[channel] = data & 0x0fff;
}
void Update() {
- GPIOB->BSRR = kPinSS;
- GPIOB->BRR = kPinSS;
- uint16_t command_nibble = (active_channel_ << 2) | 1;
+ uint16_t kPinSS = (active_channel_ >> 1) & 1 ? kPinDAC2_SS : kPinDAC1_SS;
+ GPIOA->BSRR = kPinSS;
+ GPIOA->BRR = kPinSS;
+ uint16_t command_nibble = ((active_channel_ & 1) << 3) | 3;
SPI2->DR = (command_nibble << 12) | data_[active_channel_];
active_channel_ = (active_channel_ + 1) % 4;
}