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 VNI8200XP.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 VNI8200XP
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 "VNI8200XP.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 VNI8200XP VNI8200XP
Davidroid 5:0845d4141a01 61 * @{
Davidroid 5:0845d4141a01 62 * @brief Digital Output Driver Layer
Davidroid 5:0845d4141a01 63 */
Davidroid 5:0845d4141a01 64
Davidroid 5:0845d4141a01 65 /** @defgroup VNI8200XP_Private_variables VNI8200XP Private variables
Davidroid 5:0845d4141a01 66 * @{
Davidroid 5:0845d4141a01 67 * @brief Digital Output Private variables
Davidroid 5:0845d4141a01 68 */
Davidroid 5:0845d4141a01 69
Davidroid 5:0845d4141a01 70 /* Number of components */
Davidroid 5:0845d4141a01 71 uint8_t VNI8200XP::number_of_plc_output_components = 0;
Davidroid 5:0845d4141a01 72
Davidroid 5:0845d4141a01 73
Davidroid 5:0845d4141a01 74 /** @defgroup VNI8200XP_Exported_Functions VNI8200XP 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 VNI8200XP 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 VNI8200XP::VNI8200XP_Init(void *init)
Davidroid 5:0845d4141a01 85 {
Davidroid 5:0845d4141a01 86 VNI_PARITY_Buffer = 0x00;
Davidroid 5:0845d4141a01 87 VNI_FAULT_Buffer = 0x00;
Davidroid 5:0845d4141a01 88 VNI_FB_OK = 0x00;
Davidroid 5:0845d4141a01 89 VNI_TEMP_WARNING = 0x00;
Davidroid 5:0845d4141a01 90 VNI_PARITY_CHECK = 0x00;
Davidroid 5:0845d4141a01 91 VNI_POWER_GOOD = 0x00;
Davidroid 5:0845d4141a01 92 VNI_PARITY_FALL_Buffer = 0x00;
Davidroid 5:0845d4141a01 93
Davidroid 5:0845d4141a01 94 /* Unselect the Ssrelay chip at startup to avoid FAULT */
Davidroid 5:0845d4141a01 95 ssel = 1;
Davidroid 5:0845d4141a01 96
Davidroid 5:0845d4141a01 97 /* Enable Ssrelay Outputs */
Davidroid 5:0845d4141a01 98 out_en = 1;
Davidroid 5:0845d4141a01 99
Davidroid 5:0845d4141a01 100 return COMPONENT_OK;
Davidroid 5:0845d4141a01 101 }
Davidroid 5:0845d4141a01 102
Davidroid 5:0845d4141a01 103 /**********************************************************
Davidroid 5:0845d4141a01 104 * @brief Read id
Davidroid 5:0845d4141a01 105 * @param id pointer to the identifier to be read.
Davidroid 5:0845d4141a01 106 * @retval COMPONENT_OK in case of success.
Davidroid 5:0845d4141a01 107 **********************************************************/
Davidroid 5:0845d4141a01 108 status_t VNI8200XP::VNI8200XP_ReadID(uint8_t *id)
Davidroid 5:0845d4141a01 109 {
Davidroid 5:0845d4141a01 110 *id = plc_output_component_instance;
Davidroid 5:0845d4141a01 111
Davidroid 5:0845d4141a01 112 return COMPONENT_OK;
Davidroid 5:0845d4141a01 113 }
Davidroid 5:0845d4141a01 114
Davidroid 5:0845d4141a01 115 /**********************************************************
Davidroid 5:0845d4141a01 116 * @brief Set output channels state
Davidroid 5:0845d4141a01 117 * @param Out_array, output channel data
Davidroid 5:0845d4141a01 118 * @retval None
Davidroid 5:0845d4141a01 119 **********************************************************/
Davidroid 5:0845d4141a01 120 void VNI8200XP::VNI8200XP_SetChannels(uint8_t Out_array)
Davidroid 5:0845d4141a01 121 {
Davidroid 5:0845d4141a01 122 spi_tx_buff[1] = Out_array;
Davidroid 5:0845d4141a01 123 }
Davidroid 5:0845d4141a01 124
Davidroid 5:0845d4141a01 125 /**********************************************************
Davidroid 5:0845d4141a01 126 * @brief Get output fault status
Davidroid 5:0845d4141a01 127 * @param None
Davidroid 5:0845d4141a01 128 * @retval Output channel fault data
Davidroid 5:0845d4141a01 129 **********************************************************/
Davidroid 5:0845d4141a01 130 uint8_t VNI8200XP::VNI8200XP_ManageFault(void)
Davidroid 5:0845d4141a01 131 {
Davidroid 5:0845d4141a01 132 VNI_FAULT_Buffer = spi_rx_buff[1];
Davidroid 5:0845d4141a01 133 return VNI_FAULT_Buffer;
Davidroid 5:0845d4141a01 134 }
Davidroid 5:0845d4141a01 135
Davidroid 5:0845d4141a01 136 /**********************************************************
Davidroid 5:0845d4141a01 137 * @brief Get VNI8200XP DC-DC status
Davidroid 5:0845d4141a01 138 * @param None
Davidroid 5:0845d4141a01 139 * @retval Feedback status, COMPONENT_OK if OK
Davidroid 5:0845d4141a01 140 **********************************************************/
Davidroid 5:0845d4141a01 141 status_t VNI8200XP::VNI8200XP_CheckDCDCStatus(void)
Davidroid 5:0845d4141a01 142 {
Davidroid 5:0845d4141a01 143 VNI_FB_OK = spi_rx_buff[0];
Davidroid 5:0845d4141a01 144 VNI_FB_OK = VNI_FB_OK & 0x80;
Davidroid 5:0845d4141a01 145 if(VNI_FB_OK == 0x80) {
Davidroid 5:0845d4141a01 146 return COMPONENT_ERROR;
Davidroid 5:0845d4141a01 147 } else {
Davidroid 5:0845d4141a01 148 return COMPONENT_OK;
Davidroid 5:0845d4141a01 149 }
Davidroid 5:0845d4141a01 150 }
Davidroid 5:0845d4141a01 151
Davidroid 5:0845d4141a01 152 /**********************************************************
Davidroid 5:0845d4141a01 153 * @brief Get temperature warning status
Davidroid 5:0845d4141a01 154 * @param None
Davidroid 5:0845d4141a01 155 * @retval Temperature warning status, COMPONENT_ERROR if over temperature
Davidroid 5:0845d4141a01 156 **********************************************************/
Davidroid 5:0845d4141a01 157 status_t VNI8200XP::VNI8200XP_TemperatureWarning(void)
Davidroid 5:0845d4141a01 158 {
Davidroid 5:0845d4141a01 159 VNI_TEMP_WARNING = spi_rx_buff[0];
Davidroid 5:0845d4141a01 160 VNI_TEMP_WARNING = VNI_TEMP_WARNING & 0x40;
Davidroid 5:0845d4141a01 161 if(VNI_TEMP_WARNING == 0x40) {
Davidroid 5:0845d4141a01 162 return COMPONENT_ERROR;
Davidroid 5:0845d4141a01 163 } else {
Davidroid 5:0845d4141a01 164 return COMPONENT_OK;
Davidroid 5:0845d4141a01 165 }
Davidroid 5:0845d4141a01 166 }
Davidroid 5:0845d4141a01 167
Davidroid 5:0845d4141a01 168 /**********************************************************
Davidroid 5:0845d4141a01 169 * @brief Get parity check status
Davidroid 5:0845d4141a01 170 * @param None
Davidroid 5:0845d4141a01 171 * @retval Parity check flag, COMPONENT_ERROR if 0x20
Davidroid 5:0845d4141a01 172 **********************************************************/
Davidroid 5:0845d4141a01 173 status_t VNI8200XP::VNI8200XP_CheckParity(void)
Davidroid 5:0845d4141a01 174 {
Davidroid 5:0845d4141a01 175 VNI_PARITY_CHECK = spi_rx_buff[0];
Davidroid 5:0845d4141a01 176 VNI_PARITY_CHECK = VNI_PARITY_CHECK & 0x20;
Davidroid 5:0845d4141a01 177 if(VNI_PARITY_CHECK == 0x20) {
Davidroid 5:0845d4141a01 178 return COMPONENT_ERROR;
Davidroid 5:0845d4141a01 179 } else {
Davidroid 5:0845d4141a01 180 return COMPONENT_OK;
Davidroid 5:0845d4141a01 181 }
Davidroid 5:0845d4141a01 182 }
Davidroid 5:0845d4141a01 183
Davidroid 5:0845d4141a01 184 /**********************************************************
Davidroid 5:0845d4141a01 185 * @brief Get power supply status
Davidroid 5:0845d4141a01 186 * @param None
Davidroid 5:0845d4141a01 187 * @retval Power good bit, COMPONENT_OK in case of power good
Davidroid 5:0845d4141a01 188 **********************************************************/
Davidroid 5:0845d4141a01 189 status_t VNI8200XP::VNI8200XP_CheckPowerGood(void)
Davidroid 5:0845d4141a01 190 {
Davidroid 5:0845d4141a01 191 VNI_POWER_GOOD = spi_rx_buff[0];
Davidroid 5:0845d4141a01 192 VNI_POWER_GOOD = VNI_POWER_GOOD & 0x10;
Davidroid 5:0845d4141a01 193 if(VNI_POWER_GOOD == 0x10) {
Davidroid 5:0845d4141a01 194 return COMPONENT_OK;
Davidroid 5:0845d4141a01 195 } else {
Davidroid 5:0845d4141a01 196 return COMPONENT_ERROR;
Davidroid 5:0845d4141a01 197 }
Davidroid 5:0845d4141a01 198 }
Davidroid 5:0845d4141a01 199
Davidroid 5:0845d4141a01 200 /**********************************************************
Davidroid 5:0845d4141a01 201 * @brief Get parity bits for input data from VNI
Davidroid 5:0845d4141a01 202 * @param None
Davidroid 5:0845d4141a01 203 * @retval Parity bits from VNI
Davidroid 5:0845d4141a01 204 **********************************************************/
Davidroid 5:0845d4141a01 205 uint8_t VNI8200XP::VNI8200XP_CheckCommError(void)
Davidroid 5:0845d4141a01 206 {
Davidroid 5:0845d4141a01 207 VNI_PARITY_FALL_Buffer = spi_rx_buff[0];
Davidroid 5:0845d4141a01 208 VNI_PARITY_FALL_Buffer = VNI_PARITY_FALL_Buffer & 0x0F;
Davidroid 5:0845d4141a01 209 return VNI_PARITY_FALL_Buffer;
Davidroid 5:0845d4141a01 210 }
Davidroid 5:0845d4141a01 211
Davidroid 5:0845d4141a01 212 /**********************************************************
Davidroid 5:0845d4141a01 213 * @brief Set output channels component
Davidroid 5:0845d4141a01 214 * @param txBuff
Davidroid 5:0845d4141a01 215 * @retval None
Davidroid 5:0845d4141a01 216 **********************************************************/
Davidroid 5:0845d4141a01 217 void VNI8200XP::VNI8200XP_Ssrelay_SetOutput(uint8_t *outputArray)
Davidroid 5:0845d4141a01 218 {
Davidroid 5:0845d4141a01 219 spi_tx_buff[0] = outputArray[0];
Davidroid 5:0845d4141a01 220 spi_tx_buff[1] = outputArray[1];
Davidroid 5:0845d4141a01 221
Davidroid 5:0845d4141a01 222 if(VNI8200XP_SpiWriteBytes(spi_tx_buff, spi_rx_buff) != 0) {
Davidroid 5:0845d4141a01 223 /* Aborting the program */
Davidroid 5:0845d4141a01 224 exit(EXIT_FAILURE);
Davidroid 5:0845d4141a01 225 }
Davidroid 5:0845d4141a01 226 }
Davidroid 5:0845d4141a01 227
Davidroid 5:0845d4141a01 228 /**
Davidroid 5:0845d4141a01 229 * @} //end VNI8200XP Exported Functions
Davidroid 5:0845d4141a01 230 */
Davidroid 5:0845d4141a01 231
Davidroid 5:0845d4141a01 232 /**
Davidroid 5:0845d4141a01 233 * @} //end VNI8200XP Device Driver
Davidroid 5:0845d4141a01 234 */
Davidroid 5:0845d4141a01 235 /**
Davidroid 5:0845d4141a01 236 * @} //end Components
Davidroid 5:0845d4141a01 237 */
Davidroid 5:0845d4141a01 238 /**
Davidroid 5:0845d4141a01 239 * @} //close group BSP
Davidroid 5:0845d4141a01 240 */
Davidroid 5:0845d4141a01 241
Davidroid 5:0845d4141a01 242 /**
Davidroid 5:0845d4141a01 243 * @} //close group Drivers
Davidroid 5:0845d4141a01 244 */
Davidroid 5:0845d4141a01 245
Davidroid 5:0845d4141a01 246 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/