dtmf  2.1.0.0
Main Page

DTMF click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : Oct 2023.
  • Type : SPI type

Software Support

We provide a library for the DTMF 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 DTMF Click driver.

Standard key functions :

Example key functions :

  • dtmf_handshake_init This function performs a handshake init which resets the device settings to default.
    err_t dtmf_handshake_init ( dtmf_t *ctx );
  • dtmf_dial This function dials the selected number by alternating between DTMF and No-tone.
    err_t dtmf_dial ( dtmf_t *ctx, uint8_t *dial_num );
  • dtmf_send_message This function sends an array of bytes via V.23 FSK 1200bps modem in start-stop 8.1 mode.
    err_t dtmf_send_message ( dtmf_t *ctx, uint8_t *data_in, uint8_t len );

Example Description

This example demonstrates the use of DTMF click board by showing the communication between the two click boards connected to PBX system.

The demo application is composed of two sections :

Application Init

Initializes the driver and logger, and displays the selected application mode.

void application_init ( void )
{
log_cfg_t log_cfg;
dtmf_cfg_t dtmf_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
dtmf_cfg_setup( &dtmf_cfg );
DTMF_MAP_MIKROBUS( dtmf_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == dtmf_init( &dtmf, &dtmf_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
#if ( DEMO_APP == APP_DIALING )
log_printf( &logger, " Application Mode: Dialing\r\n" );
#elif ( DEMO_APP == APP_ANSWERING )
log_printf( &logger, " Application Mode: Answering\r\n" );
#else
#error "Selected application mode is not supported!"
#endif
log_info( &logger, " Application Task " );
}

Application Task

Dialing application mode:

  • Resets the device settings and dials the selected number. If a call is answered it starts sending desired messages every couple of seconds with constantly checking if a call is still in progress or it's terminated from the other side.

Answering application mode:

  • Resets the device settings and waits for an incoming call indication, answers the call, and waits for a desired number of messages. The call is terminated after all messages are received successfully.
void application_task ( void )
{
uint8_t state = DTMF_STATE_IDLE;
uint32_t time_cnt = 0;
uint8_t msg_cnt = 0;
#if ( DEMO_APP == APP_DIALING )
log_printf( &logger, "\r\n Hook OFF\r\n" );
dtmf_hook_off ( &dtmf );
Delay_ms ( 4000 );
log_printf( &logger, " Dial: %s\r\n", ( char * ) DIAL_NUMBER );
dtmf_dial ( &dtmf, DIAL_NUMBER );
dtmf.rx_mode &= DTMF_RX_LEVEL_MASK; // No change in rx level setting
dtmf_set_receive_mode ( &dtmf, dtmf.rx_mode );
for ( ; ; )
{
Delay_ms ( 1 );
if ( !dtmf_get_irq_pin ( &dtmf ) )
{
time_cnt = 0;
}
if ( ( DTMF_STATE_IRQ_SET == state ) && !dtmf_call_progress ( &dtmf ) )
{
if ( time_cnt < DTMF_TIMING_BUSY )
{
log_printf( &logger, " Busy\r\n" );
break;
}
else if ( time_cnt < DTMF_TIMING_DISCONNECTED )
{
log_printf( &logger, " Disconnected\r\n" );
break;
}
else if ( time_cnt < DTMF_TIMING_RINGING )
{
log_printf( &logger, " Ringing\r\n" );
}
}
if ( ( DTMF_STATE_RINGING == state ) && ( time_cnt > DTMF_TIMING_CALL_PROGRESS ) )
{
log_printf( &logger, " Call in progress\r\n" );
time_cnt = 0;
}
if ( ( DTMF_STATE_CALL_IN_PROGRESS == state ) && !( time_cnt % DTMF_TIMING_SEND_MESSAGE ) )
{
log_printf( &logger, " Send message %u\r\n", ( uint16_t ) msg_cnt++ );
}
if ( time_cnt++ > DTMF_TIMEOUT_CALL_PROGRESS )
{
log_printf( &logger, " Timeout\r\n" );
break;
}
}
log_printf( &logger, " Hook ON\r\n" );
dtmf_hook_on ( &dtmf );
Delay_ms ( 4000 );
#elif ( DEMO_APP == APP_ANSWERING )
uint8_t rx_data = 0;
uint8_t msg_end_buff[ 2 ] = { 0 };
log_printf( &logger, "\r\n Waiting for a call...\r\n" );
while ( dtmf_get_rdn_pin ( &dtmf ) );
Delay_ms ( 1000 );
log_printf( &logger, " Hook OFF\r\n" );
dtmf_hook_off ( &dtmf );
Delay_ms ( 1000 );
log_printf( &logger, " Waiting for %u messages...\r\n", ( uint16_t ) NUM_MESSAGES );
dtmf.rx_mode &= DTMF_RX_LEVEL_MASK; // No change in rx level setting
dtmf_set_receive_mode ( &dtmf, dtmf.rx_mode );
for ( ; ; )
{
Delay_ms ( 1 );
if ( !dtmf_get_irq_pin ( &dtmf ) )
{
if ( DTMF_STATE_IDLE != state )
{
log_printf( &logger, "\r\n Disconnected\r\n" );
break;
}
log_printf( &logger, " Message %u: ", ( uint16_t ) msg_cnt );
time_cnt = 0;
}
if ( ( DTMF_STATE_IRQ_SET == state ) && !( time_cnt % DTMF_TIMING_RX_READY ) )
{
if ( dtmf_unscram_1s_det ( &dtmf ) && dtmf_rx_ready ( &dtmf ) )
{
dtmf_receive_data ( &dtmf, &rx_data );
log_printf( &logger, "%c", ( uint16_t ) rx_data );
if ( '\r' == rx_data )
{
msg_end_buff[ 0 ] = rx_data;
}
else if ( '\n' == rx_data )
{
msg_end_buff[ 1 ] = rx_data;
}
else
{
msg_end_buff[ 0 ] = 0;
msg_end_buff[ 1 ] = 0;
}
}
if ( ( '\r' == msg_end_buff[ 0 ] ) && ( '\n' == msg_end_buff[ 1 ] ) )
{
msg_end_buff[ 0 ] = 0;
msg_end_buff[ 1 ] = 0;
state = DTMF_STATE_IDLE;
if ( NUM_MESSAGES == ++msg_cnt )
{
Delay_ms ( 100 );
log_printf( &logger, " Terminate call\r\n" );
Delay_ms ( 100 );
break;
}
}
}
if ( time_cnt++ > DTMF_TIMING_WAIT_FOR_MESSAGE )
{
log_printf( &logger, "\r\n Timeout\r\n" );
break;
}
}
log_printf( &logger, " Hook ON\r\n" );
dtmf_hook_on ( &dtmf );
Delay_ms ( 4000 );
#endif
}

Note

We have used a Yeastar S20 VoIP PBX system for the test, where the click boards are

connected to ports 1 and 2 configured as FXS extension with numbers 1000 and 1001 (dialer).

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.DTMF

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.


DTMF_RX_MODE_DTMF_TONES
#define DTMF_RX_MODE_DTMF_TONES
Definition: dtmf.h:197
DTMF_RX_MODE_V23_FSK_1200
#define DTMF_RX_MODE_V23_FSK_1200
Definition: dtmf.h:193
DTMF_STATE_RINGING
#define DTMF_STATE_RINGING
Definition: dtmf.h:285
DTMF_RX_TONE_DETECT_CALL_PROG
#define DTMF_RX_TONE_DETECT_CALL_PROG
Definition: dtmf.h:223
dtmf_unscram_1s_det
uint8_t dtmf_unscram_1s_det(dtmf_t *ctx)
DTMF unscram 1s det function.
DTMF_TIMING_BUSY
#define DTMF_TIMING_BUSY
Definition: dtmf.h:271
DTMF_MAP_MIKROBUS
#define DTMF_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: dtmf.h:321
DTMF_TIMING_RX_READY
#define DTMF_TIMING_RX_READY
Definition: dtmf.h:276
dtmf_send_message
err_t dtmf_send_message(dtmf_t *ctx, uint8_t *data_in, uint8_t len)
DTMF send message function.
DIAL_NUMBER
#define DIAL_NUMBER
Definition: main.c:42
DTMF_RX_DATA_PARITY_8_NO_PAR
#define DTMF_RX_DATA_PARITY_8_NO_PAR
Definition: dtmf.h:214
application_task
void application_task(void)
Definition: main.c:89
DTMF_STATE_CALL_IN_PROGRESS
#define DTMF_STATE_CALL_IN_PROGRESS
Definition: dtmf.h:286
dtmf_init
err_t dtmf_init(dtmf_t *ctx, dtmf_cfg_t *cfg)
DTMF initialization function.
dtmf_call_progress
uint8_t dtmf_call_progress(dtmf_t *ctx)
DTMF call progress function.
dtmf_hook_on
void dtmf_hook_on(dtmf_t *ctx)
DTMF hook on function.
DTMF_TIMING_WAIT_FOR_MESSAGE
#define DTMF_TIMING_WAIT_FOR_MESSAGE
Definition: dtmf.h:277
dtmf_t
DTMF Click context object.
Definition: dtmf.h:338
DTMF_TIMEOUT_CALL_PROGRESS
#define DTMF_TIMEOUT_CALL_PROGRESS
Definition: dtmf.h:270
dtmf_get_rdn_pin
uint8_t dtmf_get_rdn_pin(dtmf_t *ctx)
DTMF get rdn pin function.
dtmf_hook_off
void dtmf_hook_off(dtmf_t *ctx)
DTMF hook off function.
DTMF_RX_LEVEL_MASK
#define DTMF_RX_LEVEL_MASK
Definition: dtmf.h:208
DTMF_TIMING_SEND_MESSAGE
#define DTMF_TIMING_SEND_MESSAGE
Definition: dtmf.h:275
DTMF_STATE_IRQ_SET
#define DTMF_STATE_IRQ_SET
Definition: dtmf.h:284
dtmf_rx_ready
uint8_t dtmf_rx_ready(dtmf_t *ctx)
DTMF rx ready function.
TEXT_TO_SEND
#define TEXT_TO_SEND
Definition: main.c:43
DTMF_TIMING_RINGING
#define DTMF_TIMING_RINGING
Definition: dtmf.h:273
DTMF_RX_USART_START_STOP
#define DTMF_RX_USART_START_STOP
Definition: dtmf.h:210
application_init
void application_init(void)
Definition: main.c:51
DTMF_TIMING_DISCONNECTED
#define DTMF_TIMING_DISCONNECTED
Definition: dtmf.h:272
dtmf_handshake_init
err_t dtmf_handshake_init(dtmf_t *ctx)
DTMF handshake init function.
dtmf_receive_data
err_t dtmf_receive_data(dtmf_t *ctx, uint8_t *data_out)
DTMF receive data function.
dtmf_set_receive_mode
err_t dtmf_set_receive_mode(dtmf_t *ctx, uint16_t data_in)
DTMF set receive mode function.
dtmf_get_irq_pin
uint8_t dtmf_get_irq_pin(dtmf_t *ctx)
DTMF get irq pin function.
DTMF_STATE_IDLE
#define DTMF_STATE_IDLE
DTMF state setting.
Definition: dtmf.h:283
DTMF_TIMING_CALL_PROGRESS
#define DTMF_TIMING_CALL_PROGRESS
Definition: dtmf.h:274
dtmf_cfg_setup
void dtmf_cfg_setup(dtmf_cfg_t *cfg)
DTMF configuration object setup function.
dtmf_cfg_t
DTMF Click configuration object.
Definition: dtmf.h:363
NUM_MESSAGES
#define NUM_MESSAGES
Definition: main.c:46
dtmf_dial
err_t dtmf_dial(dtmf_t *ctx, uint8_t *dial_num)
DTMF dial function.