usbcsink3  2.1.0.0
Main Page

USB-C Sink 3 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Nenad Filipovic
  • Date : Jun 2023.
  • Type : I2C/SPI type

Software Support

We provide a library for the USB-C Sink 3 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for USB-C Sink 3 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of USB-C Sink 3 Click boardâ„¢ by setting DC power requests and control for Type-C connector-equipped devices (TCD).

The demo application is composed of two sections :

Application Init

Initializes SPI, I2C and ADC modules and log UART. After driver initialization the app set default settings: Voltage Selection: 5 [V] and Power: 15.0 [W].

void application_init ( void )
{
log_cfg_t log_cfg;
usbcsink3_cfg_t usbcsink3_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
usbcsink3_cfg_setup( &usbcsink3_cfg );
USBCSINK3_MAP_MIKROBUS( usbcsink3_cfg, MIKROBUS_1 );
err_t init_flag = usbcsink3_init( &usbcsink3, &usbcsink3_cfg );
if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
Delay_ms( 100 );
if ( USBCSINK3_ERROR == usbcsink3_default_cfg ( &usbcsink3 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
Delay_ms( 100 );
log_info( &logger, " Application Task " );
log_printf( &logger, " ------------------------\r\n" );
Delay_ms( 1000 );
}

Application Task

In this example, the app configures Power Data Objects (PDO) highest priority profile and requests power from a standard USB PD source adapter. It interprets power input requirements (voltage/current and maximum power) from the TCD. The example uses two configurations:

  • Voltage 5 [V] and Power 15.0 [W]
  • Voltage 9 [V] and Power 18.0 [W] Results are being sent to the Usart Terminal where you can track their changes.
void application_task ( void )
{
static float voltage = 0.0;
{
log_printf( &logger, " Output:\r\nVoltage: 5.0 [V]\r\nPower: 15.0 [W]\r\n" );
log_printf( &logger, " - - - - - - - - - - - -\r\n" );
Delay_ms( 1000 );
usbcsink3_get_vbus ( &usbcsink3, &voltage );
log_printf( &logger, " VBUS : %.1f [V]\r\n", voltage );
log_printf( &logger, " ------------------------\r\n" );
Delay_ms( 5000 );
}
{
log_printf( &logger, " Output:\r\nVoltage: 9.0 [V]\r\nPower: 18.0 [W]\r\n" );
log_printf( &logger, " - - - - - - - - - - - -\r\n" );
Delay_ms( 1000 );
usbcsink3_get_vbus ( &usbcsink3, &voltage );
log_printf( &logger, " VBUS : %.1f [V]\r\n", voltage );
log_printf( &logger, " ------------------------\r\n" );
Delay_ms( 5000 );
}
}

Note

FAULT LED flickering notified of the system status:

  • Charging: Breathing light (2 sec dimming), 1 cycle is 4 sec.
  • Fully charged: Continuously lit Charging current < 500mA.
  • Mismatch: 1s flicker Voltage or power mismatch. Non-PD power source, 1 cycle is 2sec.
  • Fault: 300ms flicker OVP, 1 cycle is 600ms.

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.USBCSink3

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


usbcsink3_vtg_sel_t
usbcsink3_vtg_sel_t
USB-C Sink 3 Click voltage selection value data.
Definition: usbcsink3.h:290
usbcsink3_init
err_t usbcsink3_init(usbcsink3_t *ctx, usbcsink3_cfg_t *cfg)
USB-C Sink 3 initialization function.
USBCSINK3_PWR_SEL_15W
@ USBCSINK3_PWR_SEL_15W
Definition: usbcsink3.h:309
usbcsink3_cfg_t
USB-C Sink 3 Click configuration object.
Definition: usbcsink3.h:253
USBCSINK3_OK
@ USBCSINK3_OK
Definition: usbcsink3.h:280
USBCSINK3_VTG_SEL_5V
@ USBCSINK3_VTG_SEL_5V
Definition: usbcsink3.h:291
usbcsink3_cfg_setup
void usbcsink3_cfg_setup(usbcsink3_cfg_t *cfg)
USB-C Sink 3 configuration object setup function.
USBCSINK3_PWR_SEL_18W
@ USBCSINK3_PWR_SEL_18W
Definition: usbcsink3.h:310
application_task
void application_task(void)
Definition: main.c:84
USBCSINK3_ERROR
@ USBCSINK3_ERROR
Definition: usbcsink3.h:281
usbcsink3_s
USB-C Sink 3 Click context object.
Definition: usbcsink3.h:236
usbcsink3_pwr_sel_t
usbcsink3_pwr_sel_t
USB-C Sink 3 Click power selection value data.
Definition: usbcsink3.h:307
usbcsink3_get_vbus
err_t usbcsink3_get_vbus(usbcsink3_t *ctx, float *vbus)
USB-C Sink 3 get VBUS function.
usbcsink3_set_power
err_t usbcsink3_set_power(usbcsink3_t *ctx, usbcsink3_pwr_sel_t power)
USB-C Sink 3 set the power function.
usbcsink3_set_voltage
err_t usbcsink3_set_voltage(usbcsink3_t *ctx, usbcsink3_vtg_sel_t voltage)
USB-C Sink 3 set the voltage function.
USBCSINK3_VTG_SEL_9V
@ USBCSINK3_VTG_SEL_9V
Definition: usbcsink3.h:292
application_init
void application_init(void)
Definition: main.c:43
usbcsink3_default_cfg
err_t usbcsink3_default_cfg(usbcsink3_t *ctx)
USB-C Sink 3 default configuration function.
USBCSINK3_MAP_MIKROBUS
#define USBCSINK3_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: usbcsink3.h:218