element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs DAC8775 Quad-Channel DAC EVM - part 2: Firmware
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 15 Jul 2018 3:56 PM Date Created
  • Views 2233 views
  • Likes 9 likes
  • Comments 5 comments
  • dac8775
  • automotive
  • hercules
  • launchpad
  • ti_rt
Related
Recommended

DAC8775 Quad-Channel DAC EVM - part 2: Firmware

Jan Cumps
Jan Cumps
15 Jul 2018

In this post, I document the firmware I use to test the DAC8775, the subject of the Quad-Channel, Analog Output Module RoadTest.

image

I'm using a Hercules automotive microcontroller to talk to the DAC. I'll cover the peripheral configuration and the test code.

Even if you're using a different controller, the sequence of events may help you to write your own code for this DAC.

 

Connections

 

The Hercules is one of the smallest of the family, a TMS570LS04. I use this because it has all peripherals on board to do this exercise.

It's also my favourite microcontroller. We have a history together.

 

I'm using two GIO pins for the nRESET (GIO A.6) and nALERT (GIO A.7) signals. The SPI is served by the Hercules' SPI #3.

This choice is because I'm using a LaunchPad, and these pins are easily accessible.

 

DAC EVM PINSignalLaunchPad PINSignalLogic Analyser Signal
1SPI DIN (MISO)J10.12SPI3.SOMI1
2SPI nCSJ10.13SPI3.nCS03
3GNDJ2.1GNDGND
4SPI CLKJ10.11SPI3.SCLK0
5VDUTncncnc
6SPI DOUT (MOSI)J10.14SPI3.SIMO2
7nRESET inJ2.8GIOA.64
8ncncncnc
9nALARM outJ2.9GIOA.75
10ncncncnc

 

image

 

 

I've connected a volt meter over output A of the DAC board to validate behaviour.

 

Configure Hercules Peripherals

 

As usual for this controller family, I configure peripherals and drivers with the HALCoGen application.

 

Drivers and PINMUX

image

I'm using the GIO driver for the nRESET and nALARM signals. SPI3 is the SPI port of choice.

Take care that alll signals that require MUX setup are active (on the TSM570LS04 they are all active by default. If you're using another Hercules, please check).

 

image

 

GIO

 

GIOA.6 is entertaining nREST. Set it as an output port, dafault to 1.

GIOA.7 listens to nALERT. Set it as an input port. Set the pull-down resistor to prevent the pin from flapping in the breeze.

image

 

 

SPI

 

In the data format block, you define the speed (you can up the speed in real life. I'm using a breadboard so I'm restricting it to 321.5 kBaud) and the SPI word length.

This is also where you can define the clock polarity and phase.

image

 

In the Port block, you set the functionality of the SPI pins. I've set all that are used to SPI, all the rest to GIO.

image

To avoid bogus info in the nCS line, I've set the pull-down. Without thit, I get runt pules (same with MISO).

This may not be neccessary when you'e using a PCB instead of a breadboard and patch wires.

 

Firmware

 

Dependencies and Globals

 

Here the headers of the drivers are added. I've defined constants for the nRESET and nALARM signals for readability.

The buffer for SPI input and output are defined here too.

 

/* USER CODE BEGIN (1) */
#include "gio.h"
#include "spi.h"

#include <stdint.h>

#define RESET 6
#define ALARM 7


uint16 TX_Data_Master[3] = { 0x00 };
uint16 RX_Data_Master[3] = { 0x00 };
/* USER CODE END */

 

In the main() function, we first initialise GIO and SPI. At that point. The settings we've done in HALCoGen are applied.

At the end of this block, the DAC is hardware-reset by pulling the nRESET pin low and then back high.

 

int main(void)
{
/* USER CODE BEGIN (3) */
    uint32_t uLoop = 0U;
    spiDAT1_t dataconfig1_t;

    gioInit();

    dataconfig1_t.CS_HOLD = TRUE;
    dataconfig1_t.WDEL    = TRUE;
    dataconfig1_t.DFSEL   = SPI_FMT_0;
    dataconfig1_t.CSNR    = SPI_CS_0;

    /* Enable CPU Interrupt through CPSR */
    _enable_IRQ();

    spiInit();

    // reset the DAC
    gioSetBit(gioPORTA, RESET, 0);
    // 10 ns needed, the effective time is 610 ns
    gioSetBit(gioPORTA, RESET, 1);

 

Next step is a software reset.

image

    // reset
    TX_Data_Master[0] = 0x01;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0x01;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

 

Then a validation of the communication by writing the user bit and reading it back:

 

image

image

image

 

    // toggle user bit
    TX_Data_Master[0] = 0x02;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0x01;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

    // read user bit
    TX_Data_Master[0] = 0x8b;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0x00;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

    // nop should return user bit
    TX_Data_Master[0] = 0x00;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0x00;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

 

Then the functional part:

 

image

 

Enable the internal reference. The EVM doesn't have an external one.

 

 

image

 

    //
    TX_Data_Master[0] = 0x02;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0x10;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

 

Select and configure the Buck-Boost module:

image

image

 

  //
    TX_Data_Master[0] = 0x06;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0x0f;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

    //
    TX_Data_Master[0] = 0x07;
    TX_Data_Master[1] = 0x06;
    TX_Data_Master[2] = 0x1f;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

 

Select and configure the DAC output

 

image

image

 

    //
    TX_Data_Master[0] = 0x03;
    TX_Data_Master[1] = 0x00;
    TX_Data_Master[2] = 0xf0;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

    //
    TX_Data_Master[0] = 0x04;
    TX_Data_Master[1] = 0x10;
    TX_Data_Master[2] = 0x00;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

 

... and finally set the output value.

image

 

    //
    TX_Data_Master[0] = 0x05;
    TX_Data_Master[1] = 0x08;
    TX_Data_Master[2] = 0xff;
    /* Initiate SPI3 Transmit and Receive through Polling Mode */
    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 3, TX_Data_Master, RX_Data_Master);

    uLoop = 1U;
    while (uLoop) {

    }
/* USER CODE END */

 

 

image

action shot of writing 0xffff to register 0x05

 

Below is a capture of the sequence. Note that when I took the capture, I had the Buck-Boost and DAC configuration parts switched around.

That's not good, because I enabled the output too soon (when writing register 0x04).

 

image

 

image

 

In the next posts I'll review the DAC's functionality.

 

edit: source code and HALGogen / CCSv8 project files attached

 

Related Blog
DAC8775 Quad-Channel DAC EVM - unlicensed roadtest part 1: Raw SPI
DAC8775 Quad-Channel DAC EVM - part 2: Firmware
DAC8775 Quad-Channel DAC EVM - part 3: Slew Rate Control
DAC8775 Quad-Channel DAC EVM - part 4: Current Mode
DAC8775 Quad-Channel DAC EVM - part 5: HART Interface
Attachments:
TMS570LS04_DAC8775.zip
  • Sign in to reply

Top Comments

  • rachaelp
    rachaelp over 7 years ago +4
    Nicely done Jan I love the way you explain these projects, very thorough and very clear. I'm sure many people will get a lot of benefit from reading these blogs.
  • fmilburn
    fmilburn over 7 years ago +3
    Very nicely explained. I really like the way you included register documentation interspersed with the code.
  • DAB
    DAB over 7 years ago +3
    Great job Jan. DAB
  • rachaelp
    rachaelp over 7 years ago

    Nicely done Jan image

     

    I love the way you explain these projects, very thorough and very clear. I'm sure many people will get a lot of benefit from reading these blogs. image

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 7 years ago

    Source code and HALGogen / CCSv8 project files uploaded to the article above.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 7 years ago

    Nice update to your project/review.  You have done a great job of describing/documenting your setups.

    Thanks

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Great job Jan.

     

    DAB

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 7 years ago

    Very nicely explained.  I really like the way you included register documentation interspersed with the code.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube