9 years, 8 months ago.

Nucleo f334r8 Cannot use 3ch of Dacout (Analog Out) (Aoutが1chしかでない)

hello I only can use 1ch of Dac Out.

But , I can use 2ch of Dac Out in ( Nucleo L152RE ).

//// Program is Blow . 以下はプログラム //// こんにちは、 nucleo 152ですと2ch Aoutが出ますが、 334ですと1chしかAoutがでません。

334のマニアルには、下記の様に Up to three 12-bit DAC channels with analog supply from 2.4 V to 3.6 V

One 12-bit buffered DAC channel (DAC1_OUT1) and two 12-bit unbuffered DAC channels (DAC1_OUT2 and DAC2_OUT1) can となっているので3CHでそうな感じですが、 仕様的にはどうなのでしょうか?

mbed.org/users/yamasho/code/NucleoAoutTest/ にも同じのもを入れました。

  1. include "mbed.h"
  1. if defined(TARGET_NUCLEO_L152RE) AnalogOut AOutL(PA_4); AnalogOut AOutR(PA_5);
  2. elif defined(TARGET_NUCLEO_F334R8) AnalogOut AOutL(PA_4); AnalogOut AOutR(PA_5); AnalogOut AOutS(PA_6);
  3. endif uint16_t i; uint16_t SinTable[360];

int main() { float pi = 3.141592; for(i = 0 ; i < 360 ; i++) {

  1. if defined(TARGET_NUCLEO_L152RE) SinTable[i] = (float)sin(pi*i/180.0F)*0x07ff+0x0800;
  2. elif defined(TARGET_NUCLEO_F334R8) SinTable[i] = (float)sin(pi*i/180.0F)*0x07ff+0x0800;
  3. endif }

while(1) { for(i = 0 ; i < 360 ; i++) { AOutL.write_u16(SinTable[i]); AOutR.write_u16(SinTable[i]);

  1. if defined(TARGET_NUCLEO_F334R8) AOutS.write_u16(SinTable[i]);
  2. endif wait_us(1); 1 sec } } }

以上 よろしくお願いします。

3 Answers

8 years, 3 months ago.

I had the same problem and have now solved it after using a little bit of google translate magic on Jun's answer. The problem lies in mbed-dev (or mbed-src if you want to do it yourself) there was only one DAC handle setup but the STM32F334R8 has two DACs with three channels total. The exact file is here: targets/hal/TARGET_STM/TARGET_STM32F3/analogout_api.c

The fix was to make two handles and a make a pointer to the right handle for each function.

static DAC_HandleTypeDef DacHandle; 
//becomes:
static DAC_HandleTypeDef DacHandle1; 
static DAC_HandleTypeDef DacHandle2;
DAC_HandleTypeDef* DacHandle;

With a bit of jiggery pokery with & and * and -> symbols further down in the file it all works! See: https://developer.mbed.org/users/StevieWray/code/mbed-dev/rev/fe86c59be3c2 for more details.

9 years, 8 months ago.

私も3ch使いたかったので、困りました。 原因(多分合っていると思います)は、DACが2個あるのに、パラメタ保持の変数が1個分しか無いため、取り合いになってどちらかのDACしか出力できなくなります。 DAC2を使わないか、先に初期化して後でDAC1を初期化すると2ch使えますが、DAC2が使えないので意味ないですよね。 解決策ですが、mbed-srcを編集しました。 mbed-src/targets/hal/TARGET_STM/TARGET_NUCLEO_F334R8/analogout_api.c の中で static DAC_HandleTypeDef DacHandle; とDACの保持変数が一個しかないのを static DAC_HandleTypeDef DacHandle_DAC1,DacHandle_DAC2; とDAC二個分を宣言し、PA_4、PA_5、PA_6のピン名称でDAC番号を場分けしました。 今のところ、問題なく動いています。

8 years, 10 months ago.

Did you solve the problem ?