OBDII click
OBDII click offers a unique opportunity to tap into the car diagnostic systems. It features the STN1110 Multiprotocol OBD to UART Interface, developed by the ScanTool technologies. This click can be used for the communication with the Electronic Control Unit (ECU) of a vehicle, via several different OBD II diagnostic protocols such as CAN, K LINE, L LINE and J1850. The STN1110 IC is used to process requests sent by the MCU via the UART interface and return back the responses from the ECU network nodes.
click Product page
Click library
- Author : Stefan Filipovic
- Date : Jul 2023.
- Type : UART type
Software Support
We provide a library for the OBDII 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 OBDII Click driver.
Standard key functions :
obdii_cfg_setup
Config Object Initialization function.
void obdii_cfg_setup(obdii_cfg_t *cfg)
OBDII configuration object setup function.
OBDII Click configuration object.
Definition obdii.h:152
obdii_init
Initialization function.
err_t obdii_init(obdii_t *ctx, obdii_cfg_t *cfg)
OBDII initialization function.
OBDII Click context object.
Definition obdii.h:131
Example key functions :
obdii_send_command
This function sends command string by using UART serial interface.
void obdii_send_command(obdii_t *ctx, uint8_t *cmd)
OBDII send command function.
obdii_generic_read
This function reads a desired number of data bytes by using UART serial interface.
err_t obdii_generic_read(obdii_t *ctx, uint8_t *data_out, uint16_t len)
OBDII data reading function.
obdii_reset_device
This function resets the device by toggling the RST pin.
void obdii_reset_device(obdii_t *ctx)
OBDII reset device function.
Example Description
This example demonstrates the use of OBDII click board by reading the engine RPM and vehicle speed and displaying results on the USB UART.
The demo application is composed of two sections :
Application Init
Initializes the driver and performs the click default configuration.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
if ( UART_ERROR ==
obdii_init( &obdii, &obdii_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
obdii_process ( &obdii );
obdii_clear_app_buf ( );
log_printf( &logger, "> Reset device\r\n" );
obdii_log_app_buf ( );
Delay_ms ( 1000 );
log_printf( &logger, " Disable echo\r\n" );
obdii_log_app_buf ( );
log_printf( &logger, " Remove spaces\r\n" );
obdii_log_app_buf ( );
}
#define OBDII_CMD_DISABLE_ECHO
Definition obdii.h:74
#define OBDII_RSP_PROMPT
Definition obdii.h:89
#define OBDII_CMD_SPACES_OFF
Definition obdii.h:77
#define OBDII_CMD_RESET_DEVICE
Definition obdii.h:79
#define OBDII_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition obdii.h:117
void application_init(void)
Definition main.c:80
Application Task
Reads and processes the engine RPM and vehicle speed and displays the results on the USB UART once per second.
{
uint8_t * __generic_ptr start_ptr = NULL;
uint8_t data_buf[ 5 ] = { 0 };
uint16_t rpm = 0;
uint8_t speed = 0;
log_printf( &logger, " Get current RPM\r\n" );
if ( start_ptr )
{
memcpy ( data_buf, ( start_ptr + 4 ), 4 );
data_buf[ 4 ] = 0;
rpm = hex_to_uint16( data_buf ) / 4;
log_printf( &logger, "RPM: %u\r\n\n>", rpm );
}
else
{
obdii_log_app_buf ( );
}
log_printf( &logger, " Get current speed\r\n" );
if ( start_ptr )
{
memcpy ( data_buf, ( start_ptr + 4 ), 2 );
data_buf[ 2 ] = 0;
speed = hex_to_uint8( data_buf );
log_printf( &logger, "Speed: %u km/h\r\n\n>", ( uint16_t ) speed );
}
else
{
obdii_log_app_buf ( );
}
Delay_ms ( 1000 );
}
#define OBDII_CMD_GET_CURRENT_SPEED
Definition obdii.h:81
#define OBDII_RSP_CURRENT_SPEED
Definition obdii.h:91
#define OBDII_RSP_CURRENT_RPM
Definition obdii.h:90
#define OBDII_CMD_GET_CURRENT_RPM
Definition obdii.h:80
void application_task(void)
Definition main.c:128
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.OBDII
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.