Library to handle the X-NUCLEO-PLC01A1 Programmable Logic Controller Expansion Board based on the VNI8200XP (solid state relay) and CLT01-38SQ7 (octal digital termination array) components.

Dependents:   HelloWorld_PLC01A1

Programmable Logic Controller Library

Library to handle the X-NUCLEO-PLC01A1 Programmable Logic Controller Expansion Board based on the VNI8200XP (solid state relay) and CLT01-38SQ7 (octal digital termination array) components.

Information

For further details on VNI8200XP (Octal high side smart power solid state relay with serial/parallel selectable interface on chip) please refer to ST's web site.

For further details on CLT01-38SQ7 (High speed digital input current limiter) please refer to ST's web site.

SPI configuration

Pin D3 and D13 providing the SPI serial clock are short-circuited in the X-NUCLEO-PLC01A1 Expansion Board.

Please be aware that you may not drive the base board LED if it is connected to pin D13 (as it happens on STM32 Nucleo boards) or D3, otherwise you will get a conflict.

Platform compatibility

  • STM32 NUCLEO boards have been tested with the default configuration provided by the HelloWorld_PLC01A1 example.

return DSPI_HAL_ReadData(spi_address[obj->instance]);

X-NUCLEO-PLC01A1 board powering and startup

The following steps must be followed to run the X-NUCLEO-PLC01A1:

  1. Plug the X-NUCLEO-PLC01A1 onto a base board
  2. Connect the base board to a PC via a standard Type A / mini (or micro) B USB cable
  3. Download the firmware on the MCU hosted on the base board
  4. Supply 24 V to the X-NUCLEO-PLC01A1 board through the J8 connector
  5. The HelloWorld_PLC01A1 demonstration firmware is ready to run: connect any of the 8 inputs on the J8 connector to see the corresponding output on the J10 connector capable of driving a load (i.e. short-circuit input “x” with the 24 V and connect the corresponding output “x” to a load).
Committer:
Davidroid
Date:
Thu Jul 13 16:43:31 2017 +0000
Revision:
5:0845d4141a01
Aligning to ARM mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 5:0845d4141a01 1 /**
Davidroid 5:0845d4141a01 2 ******************************************************************************
Davidroid 5:0845d4141a01 3 * @file CLT01_38S_class.cpp
Davidroid 5:0845d4141a01 4 * @author System Lab Noida
Davidroid 5:0845d4141a01 5 * @version V1.0.0
Davidroid 5:0845d4141a01 6 * @date 08-July-2015
Davidroid 5:0845d4141a01 7 * @brief PLC_CLT01-38SQ7
Davidroid 5:0845d4141a01 8 * This file provides firmware functions for how to manage I/O from CLT01-38SQ7
Davidroid 5:0845d4141a01 9 ==============================================================================
Davidroid 5:0845d4141a01 10
Davidroid 5:0845d4141a01 11
Davidroid 5:0845d4141a01 12 ******************************************************************************
Davidroid 5:0845d4141a01 13 * @attention
Davidroid 5:0845d4141a01 14 *
Davidroid 5:0845d4141a01 15 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Davidroid 5:0845d4141a01 16 *
Davidroid 5:0845d4141a01 17 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 5:0845d4141a01 18 * are permitted provided that the following conditions are met:
Davidroid 5:0845d4141a01 19 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 5:0845d4141a01 20 * this list of conditions and the following disclaimer.
Davidroid 5:0845d4141a01 21 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 5:0845d4141a01 22 * this list of conditions and the following disclaimer in the documentation
Davidroid 5:0845d4141a01 23 * and/or other materials provided with the distribution.
Davidroid 5:0845d4141a01 24 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 5:0845d4141a01 25 * may be used to endorse or promote products derived from this software
Davidroid 5:0845d4141a01 26 * without specific prior written permission.
Davidroid 5:0845d4141a01 27 *
Davidroid 5:0845d4141a01 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 5:0845d4141a01 29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 5:0845d4141a01 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 5:0845d4141a01 31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 5:0845d4141a01 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 5:0845d4141a01 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 5:0845d4141a01 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 5:0845d4141a01 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 5:0845d4141a01 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 5:0845d4141a01 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 5:0845d4141a01 38 *
Davidroid 5:0845d4141a01 39 ******************************************************************************
Davidroid 5:0845d4141a01 40 */
Davidroid 5:0845d4141a01 41
Davidroid 5:0845d4141a01 42 /* Includes ------------------------------------------------------------------*/
Davidroid 5:0845d4141a01 43 #include "plc.h"
Davidroid 5:0845d4141a01 44
Davidroid 5:0845d4141a01 45 #include "CLT01_38S.h"
Davidroid 5:0845d4141a01 46
Davidroid 5:0845d4141a01 47 /** @addtogroup Drivers Drivers
Davidroid 5:0845d4141a01 48 * @{
Davidroid 5:0845d4141a01 49 * @brief Demo Driver Layer
Davidroid 5:0845d4141a01 50 */
Davidroid 5:0845d4141a01 51
Davidroid 5:0845d4141a01 52 /** @addtogroup BSP BSP
Davidroid 5:0845d4141a01 53 * @{
Davidroid 5:0845d4141a01 54 */
Davidroid 5:0845d4141a01 55
Davidroid 5:0845d4141a01 56 /** @addtogroup Components Components
Davidroid 5:0845d4141a01 57 * @{
Davidroid 5:0845d4141a01 58 */
Davidroid 5:0845d4141a01 59
Davidroid 5:0845d4141a01 60 /** @defgroup CLT01_38S CLT01_38S
Davidroid 5:0845d4141a01 61 * @{
Davidroid 5:0845d4141a01 62 * @brief Digital Input Driver Layer
Davidroid 5:0845d4141a01 63 */
Davidroid 5:0845d4141a01 64
Davidroid 5:0845d4141a01 65 /** @defgroup CLT01_38S_Private_variables CLT01 38S Private variables
Davidroid 5:0845d4141a01 66 * @{
Davidroid 5:0845d4141a01 67 * @brief Digital Input Private variables
Davidroid 5:0845d4141a01 68 */
Davidroid 5:0845d4141a01 69
Davidroid 5:0845d4141a01 70 /* Number of components */
Davidroid 5:0845d4141a01 71 uint8_t CLT01_38S::number_of_plc_input_components = 0;
Davidroid 5:0845d4141a01 72
Davidroid 5:0845d4141a01 73
Davidroid 5:0845d4141a01 74 /** @defgroup CLT01_38S_Exported_Functions CLT01 38S Exported Functions
Davidroid 5:0845d4141a01 75 * @{
Davidroid 5:0845d4141a01 76 * @brief Digital Input exported Function
Davidroid 5:0845d4141a01 77 */
Davidroid 5:0845d4141a01 78
Davidroid 5:0845d4141a01 79 /**********************************************************
Davidroid 5:0845d4141a01 80 * @brief Starts the CLT01_38S library
Davidroid 5:0845d4141a01 81 * @param init Initialization structure.
Davidroid 5:0845d4141a01 82 * @retval COMPONENT_OK in case of success.
Davidroid 5:0845d4141a01 83 **********************************************************/
Davidroid 5:0845d4141a01 84 status_t CLT01_38S::CLT01_38S_Init(void *init)
Davidroid 5:0845d4141a01 85 {
Davidroid 5:0845d4141a01 86 OTA_Buffer = 0x00;
Davidroid 5:0845d4141a01 87 CLT_PARITY_Buffer = 0x00;
Davidroid 5:0845d4141a01 88 UVA_Buffer = 0x00;
Davidroid 5:0845d4141a01 89 CLT_INPUT_STATUS_Buffer = 0x00;
Davidroid 5:0845d4141a01 90 FLAG_CLT_READ = 0;
Davidroid 5:0845d4141a01 91
Davidroid 5:0845d4141a01 92 /* Unselect the CLT chip at startup to avoid FAULT */
Davidroid 5:0845d4141a01 93 ssel = 1;
Davidroid 5:0845d4141a01 94
Davidroid 5:0845d4141a01 95 return COMPONENT_OK;
Davidroid 5:0845d4141a01 96 }
Davidroid 5:0845d4141a01 97
Davidroid 5:0845d4141a01 98 /**********************************************************
Davidroid 5:0845d4141a01 99 * @brief Read id
Davidroid 5:0845d4141a01 100 * @param id pointer to the identifier to be read.
Davidroid 5:0845d4141a01 101 * @retval COMPONENT_OK in case of success.
Davidroid 5:0845d4141a01 102 **********************************************************/
Davidroid 5:0845d4141a01 103 status_t CLT01_38S::CLT01_38S_ReadID(uint8_t *id)
Davidroid 5:0845d4141a01 104 {
Davidroid 5:0845d4141a01 105 *id = plc_input_component_instance;
Davidroid 5:0845d4141a01 106
Davidroid 5:0845d4141a01 107 return COMPONENT_OK;
Davidroid 5:0845d4141a01 108 }
Davidroid 5:0845d4141a01 109
Davidroid 5:0845d4141a01 110 /**********************************************************
Davidroid 5:0845d4141a01 111 * @brief CLT Read Status
Davidroid 5:0845d4141a01 112 * @param None
Davidroid 5:0845d4141a01 113 * @retval Status
Davidroid 5:0845d4141a01 114 **********************************************************/
Davidroid 5:0845d4141a01 115 uint8_t CLT01_38S::CLT01_38S_GetReadStatus(void)
Davidroid 5:0845d4141a01 116 {
Davidroid 5:0845d4141a01 117 return FLAG_CLT_READ;
Davidroid 5:0845d4141a01 118 }
Davidroid 5:0845d4141a01 119
Davidroid 5:0845d4141a01 120 /**********************************************************
Davidroid 5:0845d4141a01 121 * @brief Set CLT Read Status
Davidroid 5:0845d4141a01 122 * @param Status
Davidroid 5:0845d4141a01 123 * @retval None
Davidroid 5:0845d4141a01 124 **********************************************************/
Davidroid 5:0845d4141a01 125 void CLT01_38S::CLT01_38S_SetReadStatus(uint8_t status)
Davidroid 5:0845d4141a01 126 {
Davidroid 5:0845d4141a01 127 FLAG_CLT_READ = status;
Davidroid 5:0845d4141a01 128 }
Davidroid 5:0845d4141a01 129
Davidroid 5:0845d4141a01 130 /**********************************************************
Davidroid 5:0845d4141a01 131 * @brief INPUT status
Davidroid 5:0845d4141a01 132 * @param None
Davidroid 5:0845d4141a01 133 * @retval Channels status corresponding to 8 inputs
Davidroid 5:0845d4141a01 134 **********************************************************/
Davidroid 5:0845d4141a01 135 uint8_t CLT01_38S::CLT01_38S_GetInputData(void)
Davidroid 5:0845d4141a01 136 {
Davidroid 5:0845d4141a01 137 CLT_INPUT_STATUS_Buffer = spi_rx_buff[1];
Davidroid 5:0845d4141a01 138
Davidroid 5:0845d4141a01 139 return CLT_INPUT_STATUS_Buffer;
Davidroid 5:0845d4141a01 140 }
Davidroid 5:0845d4141a01 141
Davidroid 5:0845d4141a01 142 /**********************************************************
Davidroid 5:0845d4141a01 143 * @brief CLT Over_Temprature_Alarm
Davidroid 5:0845d4141a01 144 * @param None
Davidroid 5:0845d4141a01 145 * @retval Overtemperature bit, COMPONENT_ERROR in case of alarm
Davidroid 5:0845d4141a01 146 **********************************************************/
Davidroid 5:0845d4141a01 147 status_t CLT01_38S::CLT01_38S_OverTempAlarm(void)
Davidroid 5:0845d4141a01 148 {
Davidroid 5:0845d4141a01 149 OTA_Buffer = spi_rx_buff[0];
Davidroid 5:0845d4141a01 150 OTA_Buffer = OTA_Buffer & (0x40);
Davidroid 5:0845d4141a01 151
Davidroid 5:0845d4141a01 152 if(OTA_Buffer == 0x40) {
Davidroid 5:0845d4141a01 153 return COMPONENT_OK;
Davidroid 5:0845d4141a01 154 } else {
Davidroid 5:0845d4141a01 155 return COMPONENT_ERROR;
Davidroid 5:0845d4141a01 156 }
Davidroid 5:0845d4141a01 157 }
Davidroid 5:0845d4141a01 158
Davidroid 5:0845d4141a01 159 /**********************************************************
Davidroid 5:0845d4141a01 160 * @brief CLT Parity_Check_bits
Davidroid 5:0845d4141a01 161 * @param None
Davidroid 5:0845d4141a01 162 * @retval Parity bits for diagnosing inconsistency in data transmission
Davidroid 5:0845d4141a01 163 **********************************************************/
Davidroid 5:0845d4141a01 164 uint8_t CLT01_38S::CLT01_38S_CheckParity(void)
Davidroid 5:0845d4141a01 165 {
Davidroid 5:0845d4141a01 166 CLT_PARITY_Buffer = spi_rx_buff[0];
Davidroid 5:0845d4141a01 167 CLT_PARITY_Buffer = CLT_PARITY_Buffer & (0x3C);
Davidroid 5:0845d4141a01 168 CLT_PARITY_Buffer = CLT_PARITY_Buffer >> 2;
Davidroid 5:0845d4141a01 169 return CLT_PARITY_Buffer;
Davidroid 5:0845d4141a01 170 }
Davidroid 5:0845d4141a01 171
Davidroid 5:0845d4141a01 172 /**********************************************************
Davidroid 5:0845d4141a01 173 * @brief CLT Under_Voltage_Alarm_bit
Davidroid 5:0845d4141a01 174 * @param None
Davidroid 5:0845d4141a01 175 * @retval Under voltage alarm bit, COMPONENT_ERROR in case of alarm
Davidroid 5:0845d4141a01 176 **********************************************************/
Davidroid 5:0845d4141a01 177 status_t CLT01_38S::CLT01_38S_UnderVoltAlarm(void)
Davidroid 5:0845d4141a01 178 {
Davidroid 5:0845d4141a01 179 UVA_Buffer = spi_rx_buff[0];
Davidroid 5:0845d4141a01 180 UVA_Buffer = UVA_Buffer & (0x80);
Davidroid 5:0845d4141a01 181
Davidroid 5:0845d4141a01 182 if(UVA_Buffer == 0x80) {
Davidroid 5:0845d4141a01 183 return COMPONENT_OK;
Davidroid 5:0845d4141a01 184 } else{
Davidroid 5:0845d4141a01 185 return COMPONENT_ERROR;
Davidroid 5:0845d4141a01 186 }
Davidroid 5:0845d4141a01 187 }
Davidroid 5:0845d4141a01 188
Davidroid 5:0845d4141a01 189 /**********************************************************
Davidroid 5:0845d4141a01 190 * @brief Get input information from input channels component
Davidroid 5:0845d4141a01 191 * @param rxBuff
Davidroid 5:0845d4141a01 192 * @retval None
Davidroid 5:0845d4141a01 193 **********************************************************/
Davidroid 5:0845d4141a01 194 void CLT01_38S::CLT01_38S_DigInpArray_GetInput(uint8_t *inputArray)
Davidroid 5:0845d4141a01 195 {
Davidroid 5:0845d4141a01 196 if(CLT01_38S_SpiReadBytes(spi_tx_buff, spi_rx_buff) != 0) {
Davidroid 5:0845d4141a01 197 /* Aborting the program */
Davidroid 5:0845d4141a01 198 exit(EXIT_FAILURE);
Davidroid 5:0845d4141a01 199 }
Davidroid 5:0845d4141a01 200 inputArray[0] = spi_rx_buff[0];
Davidroid 5:0845d4141a01 201 inputArray[1] = spi_rx_buff[1];
Davidroid 5:0845d4141a01 202 }
Davidroid 5:0845d4141a01 203
Davidroid 5:0845d4141a01 204 /**
Davidroid 5:0845d4141a01 205 * @} //end CLT01_38S Exported Functions
Davidroid 5:0845d4141a01 206 */
Davidroid 5:0845d4141a01 207
Davidroid 5:0845d4141a01 208 /**
Davidroid 5:0845d4141a01 209 * @} //end CLT01_38S Device Driver
Davidroid 5:0845d4141a01 210 */
Davidroid 5:0845d4141a01 211 /**
Davidroid 5:0845d4141a01 212 * @} //end Components
Davidroid 5:0845d4141a01 213 */
Davidroid 5:0845d4141a01 214 /**
Davidroid 5:0845d4141a01 215 * @} //close group BSP
Davidroid 5:0845d4141a01 216 */
Davidroid 5:0845d4141a01 217
Davidroid 5:0845d4141a01 218 /**
Davidroid 5:0845d4141a01 219 * @} //close group Drivers
Davidroid 5:0845d4141a01 220 */
Davidroid 5:0845d4141a01 221
Davidroid 5:0845d4141a01 222 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/