ECG 2 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.
- Author : Stefan Ilic
- Date : Nov 2021.
- Type : SPI type
This is an example that demonstrates the use of the ECG 2 Click board.
- MikroSDK.Board
- MikroSDK.Log
- Click.ECG2
ecg2_cfg_setup
Config Object Initialization function.
void ecg2_cfg_setup ( ecg2_cfg_t *cfg );
ecg2_init
Initialization function.
err_t ecg2_init ( ecg2_t *ctx, ecg2_cfg_t *cfg );
ecg2_default_cfg
Click Default Configuration function.
err_t ecg2_default_cfg ( ecg2_t *ctx );
ecg2_read_an_pin_value
ECG 2 read AN pin value function.
err_t ecg2_read_an_pin_value ( ecg2_t *ctx, uint16_t *data_out );
ecg2_send_command
ECG 2 send command function.
err_t ecg2_send_command ( ecg2_t *ctx, uint8_t command );
ecg2_read_channel_data
ECG 2 read data channel function.
void ecg2_read_channel_data ( ecg2_t *ctx, uint8_t channel, uint16_t *data_out );
Initializes SPI and UART communication, configures INT pin as INPUT, RST pin as OUTPUT, CS pin as OUTPUT and PWM pin as OUTPUT. Initializes SPI driver, initializes ECG2 Click, sends START and RDATAC opcodes.
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
ecg2_cfg_t ecg2_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.
ecg2_cfg_setup( &ecg2_cfg );
ECG2_MAP_MIKROBUS( ecg2_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == ecg2_init( &ecg2, &ecg2_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
SET_SPI_DATA_SAMPLE_EDGE;
if ( ECG2_ERROR == ecg2_default_cfg ( &ecg2 ) )
{
log_error( &logger, " Default configuration." );
for ( ; ; );
}
Delay_ms ( 100 );
ecg2_send_command( &ecg2, ECG2_START_CONVERSION );
Delay_ms ( 100 );
ecg2_send_command( &ecg2, ECG2_ENABLE_READ_DATA_CONT_MODE );
Delay_ms ( 100 );
log_info( &logger, " Application Task " );
Delay_ms ( 100 );
}
Captures readings from channel and plots data to serial plotter.
void application_task ( void )
{
uint16_t ecg_an = 0;
ecg2_read_channel_data( &ecg2, 5, &ecg_an );
log_printf( &logger, " %.6u, %.8lu \r\n", ecg_an, time );
time += 5;
Delay_ms ( 5 );
}
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.
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.