Intermediate
30 min

Improve system reliability with TLP241A and STM32F407VGT6 through robust electrical isolation

Elevate signal integrity: OptoLink isolation at Its best!

Opto 3 Click with Clicker 4 for STM32F4

Published Dec 29, 2023

Click board™

Opto 3 Click

Dev Board

Clicker 4 for STM32F4

Compiler

NECTO Studio

MCU

STM32F407VGT6

Provide complete electrical isolation, ensuring your sensitive signals remain unaffected by external interference.

A

A

Hardware Overview

How does it work?

Opto 3 Click is based on two pairs of normally opened, high-quality solid-state relays labeled as TLP241A, from Toshiba Semiconductor. The TLP241A is an optically isolated solid-state relay (SSR), featuring an integrated IR LED and two output MOSFETs. The output stage does not have any electrical contact with the input stage; it is activated by infrared light, produced by an integrated IR LED. This allows reinforced galvanic isolation between the input and the output stage. The output stage can sustain up to 40V while OFF. When activated, due to a very low RDSON of the integrated MOSFETs, it can conduct up to 2A of current. The TLP241A are able to effectively replace traditionally used mechanical relays, bringing up the full set of inherited benefits: virtually unlimited number of cycles since there are no moving parts that would wear off, no bouncing effect on the output contacts, high resistance to mechanical shock and environmental influence, low current required for the activation, constant resistance since no carbon and rust can build up on contacts, there is no sparking or electric arc forming while operated, compact size, higher isolation voltage, and so on. However, unlike optocouplers (similar devices which are designed for much lower currents and voltages), SSRs are not designed

to be used as signal line isolators. SSR typically has a slow signal propagation time. Still, it can be used for various communication protocols which use lower data rates, including UART/RS232, 1-Wire, and similar. One pair of SSRs is driven by the host MCU. This pair can be used to activate an external circuit, utilizing the full potential of the TLP241A SSR. One or two SSRs can be used as relays, allowing the host MCU to control heavier loads such as DC motors, some other electrical circuit which operates on higher potential, LED strips, LED arrays, and more. A HIGH logic level on mikroBUS™ pins AN or RST labeled as OU1 and OU2 respectively, will activate the integrated IR LED. It will turn ON the MOSFETs in the SSR, allowing the current to flow through an external circuit. Two red LEDs, labeled as OUT1 and OUT 2, are connected to each of the MCU output pins. These LEDs provide visual feedback about the SSR state: if ON, the respective SSR is in a conductive state. SSR outputs are routed to two screw terminals labeled as OUT1 and OUT2, allowing an external circuit to be securely connected. The other pair of SSRs is used to provide optical isolation for external signals, offering protection for sensitive MCU pins that way. While the SSR is not activated, PWM and INT pins of the mikroBUS™

labeled as IN1 and IN2 respectively, are pulled to a HIGH logic level by a resistor. A signal on the input terminal will activate the respective SSR, pulling the IN1 (IN2) pin to a LOW logic level. Since galvanically isolated, the signal at the input terminal can be at a different potential than the host MCU, preventing any stray currents to flow between two GNDs. This will also protect the host MCU from the electrostatic discharge (ESD) that might occur. It is important to connect the input signal correctly. Therefore, two input terminals have their ports clearly labeled with + and - signs. A Schottky diode in series provides some protection to the input IR LED, however, care should be taken not to exceed specifications from the TLP241A datasheet. Pull-up resistors on the input side SSRs are connected to the power supply from mikroBUS™, providing a HIGH logic level while the SSR is not active. The voltage of the power supply directly determines the voltage level that will be applied to IN1 and IN2 pins in this case. Therefore, an SMD jumper labeled as VCC SEL is provided on the Click board™, allowing the user to select the logic voltage level between 3.3V and 5V, depending on the used MCU and its capabilities.

Opto 3 Click top side image
Opto 3 Click bottom side image

Features overview

Development board

Clicker 4 for STM32F4 is a compact development board designed as a complete solution that you can use to quickly build your own gadgets with unique functionalities. Featuring an STM32F407VGT6 MCU, four mikroBUS™ sockets for Click boards™ connectivity, power management, and more, it represents a perfect solution for the rapid development of many different types of applications. At its core is an STM32F407VGT6 MCU, a powerful microcontroller by STMicroelectronics based on the high-performance

Arm® Cortex®-M4 32-bit processor core operating at up to 168 MHz frequency. It provides sufficient processing power for the most demanding tasks, allowing Clicker 4 to adapt to any specific application requirements. Besides two 1x20 pin headers, four improved mikroBUS™ sockets represent the most distinctive connectivity feature, allowing access to a huge base of Click boards™, growing on a daily basis. Each section of Clicker 4 is clearly marked, offering an intuitive and clean interface. This makes working with the

development board much simpler and, thus, faster. The usability of Clicker 4 doesn’t end with its ability to accelerate the prototyping and application development stages: it is designed as a complete solution that can be implemented directly into any project, with no additional hardware modifications required. Four mounting holes [4.2mm/0.165”] at all four corners allow simple installation by using mounting screws.

Clicker 4 for STM32F4 double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M4

MCU Memory (KB)

10

Silicon Vendor

STMicroelectronics

Pin count

100

RAM (Bytes)

100

Used MCU Pins

mikroBUS™ mapper

Relay 1 Output
PC4
AN
Relay 2 Output
PC15
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Relay 1 Input
PE9
PWM
Relay 2 Input
PD0
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

Opto 3 Click Schematic schematic

Step by step

Project assembly

Clicker 4 for STM32F4 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Clicker 4 for STM32F4 as your development board.

Clicker 4 for STM32F4 front image hardware assembly
LTE IoT 5 Click front image hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Clicker 4 STM32F4 Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Clicker 4 for STM32F4 HA MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for Opto 3 Click driver.

Key functions:

  • opto3_get_in1 - This function gets input 1 pin state

  • opto3_get_in2 - This function gets input 2 pin state

  • opto3_set_out1 - This function sets output 1 pin state.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief Opto 3 Click example
 * 
 * # Description
 * Opto 3 click to be used in applications that require reinforced galvanic 
 * isolation for both their input and output stages.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes GPIO interface.
 * 
 * ## Application Task 
 * Reads the input pins state and sets their respective output pins to the same logic state.
 * The output pins state will be displayed on the USB UART where you can track their changes.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "opto3.h"

// ------------------------------------------------------------------ VARIABLES

static opto3_t opto3;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    opto3_cfg_t cfg;

    /** 
     * 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.
    opto3_cfg_setup( &cfg );
    OPTO3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    opto3_init( &opto3, &cfg );

    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    static uint8_t out1_state = 0;
    static uint8_t out2_state = 0;
    uint8_t in1_state = 0;
    uint8_t in2_state = 0;

    in1_state = opto3_get_in1( &opto3 );
    in2_state = opto3_get_in2( &opto3 );
    
    if ( in1_state != out1_state )
    {
        out1_state = in1_state;
        opto3_set_out1( &opto3, out1_state );
        log_printf( &logger, " OUT1 state: %u\r\n", ( uint16_t ) out1_state );
    }
    
    if ( in2_state != out2_state )
    {
        out2_state = in2_state;
        opto3_set_out2( &opto3, out2_state );
        log_printf( &logger, " OUT2 state: %u\r\n", ( uint16_t ) out2_state );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}


// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.