Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md


DAC 22 Click

DAC 22 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Stefan Filipovic
  • Date : Mar 2026.
  • Type : SPI type

Software Support

Example Description

This example demonstrates the control of DAC output voltage using the DAC 22 Click board. The application sequentially increases the DAC output voltage on both channels in equal steps.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.DAC22

Example Key Functions

  • dac22_cfg_setup This function initializes Click configuration structure to initial values.
void dac22_cfg_setup ( dac22_cfg_t *cfg );
  • dac22_init This function initializes all necessary pins and peripherals used for this Click board.
err_t dac22_init ( dac22_t *ctx, dac22_cfg_t *cfg );
  • dac22_default_cfg This function executes a default configuration of DAC 22 Click board.
err_t dac22_default_cfg ( dac22_t *ctx );
  • dac22_set_dac_value This function writes the 12-bit DAC code value to one or more channels and latches the output values by toggling the LAT pin.
err_t dac22_set_dac_value ( dac22_t *ctx, uint8_t channel, uint16_t value );
  • dac22_set_dac_voltage This function sets the output voltage for one or more channels by converting it to a corresponding DAC code and updating the device.
err_t dac22_set_dac_voltage ( dac22_t *ctx, uint8_t channel, uint16_t voltage_mv );

Application Init

Initializes the driver and performs the Click default configuration.

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    dac22_cfg_t dac22_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    dac22_cfg_setup( &dac22_cfg );
    DAC22_MAP_MIKROBUS( dac22_cfg, MIKROBUS_POSITION_DAC22 );
    if ( SPI_MASTER_ERROR == dac22_init( &dac22, &dac22_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( DAC22_ERROR == dac22_default_cfg ( &dac22 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

Application Task

Gradually increases the DAC output voltage on both channels in equal steps every 2 seconds.

void application_task ( void )
{
    uint16_t step = DAC22_VREF_INT / NUMBER_OF_STEPS;
    uint16_t output_voltage = step;
    for ( uint8_t cnt = 0; cnt < NUMBER_OF_STEPS; cnt++ )
    {
        if ( DAC22_OK == dac22_set_dac_voltage ( &dac22, DAC22_CHANNEL_ALL, output_voltage ) )
        {
            log_printf ( &logger, " All channels output voltage set to %u mV\r\n", output_voltage );
        }
        output_voltage += step;
        Delay_ms ( 1000 ); 
        Delay_ms ( 1000 );
    }
}

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.