parent
9cae7c38f9
commit
3e8aa6488c
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,71 @@ |
||||
<?php |
||||
|
||||
$json = file_get_contents("msg.json"); |
||||
$arr = json_decode($json); |
||||
|
||||
$table = []; |
||||
foreach($arr as $msg) { |
||||
$msg = (array)$msg; |
||||
if ($msg['port'] == 68 && $msg['dev_id'] == 'ondrej_hruska') { |
||||
$table[] = [ |
||||
'counter' => $msg['counter'], |
||||
'date' => ((array)$msg['metadata'])['time'], |
||||
'payload_raw' => $msg['payload_raw'], |
||||
'payload' => parsePayload($msg['payload_raw']), |
||||
]; |
||||
} |
||||
} |
||||
|
||||
print_r($table); |
||||
|
||||
$fil = "Counter\tDate\tTemperature [°C]\tHumidity [%RH]\tPressure [hPa]\tGas_R [Ohm]\n"; |
||||
foreach($table as $row) { |
||||
$p = $row['payload']; |
||||
$fil .= "$row[counter]\t$row[date]\t$p[temp]\t$p[hum]\t$p[press]\t$p[gas_r]\n"; |
||||
} |
||||
|
||||
file_put_contents("msg.csv", $fil); |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function parsePayload($pl64) { |
||||
$pl = base64_decode($pl64); |
||||
|
||||
/* |
||||
pb_i16(&pb, voc_data.temperature); // Cx100 |
||||
pb_u16(&pb, (uint16_t) (voc_data.humidity / 10)); // discard one place -> %x100 |
||||
pb_u16(&pb, (uint16_t) (voc_data.pressure - 85000)); // send offset from 850 hPa -> Pa |
||||
pb_u32(&pb, (uint16_t) (voc_data.gas_resistance)); // ohms, full size |
||||
*/ |
||||
$res = []; |
||||
$t = (ord($pl[0])<<8 | ord($pl[1])); |
||||
if ($t&0x8000) $t = ~$t - 1; |
||||
$res['temp'] = $t/100; |
||||
|
||||
$t = (ord($pl[2])<<8 | ord($pl[3])); |
||||
$res['hum'] = $t/100; |
||||
|
||||
$t = (ord($pl[4])<<8 | ord($pl[5])); |
||||
$res['press'] = (85000+$t)/100; |
||||
|
||||
$t = (ord($pl[6])<<24 | ord($pl[7])<<16 | ord($pl[8])<<8 | ord($pl[9])); |
||||
$res['gas_r'] = $t; |
||||
|
||||
return $res; |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
@ -0,0 +1,116 @@ |
||||
[ |
||||
{ |
||||
"id": "39e98fa5.fea9e8", |
||||
"type": "tab", |
||||
"label": "Flow 1" |
||||
}, |
||||
{ |
||||
"id": "fc3137ff.fc017", |
||||
"type": "mqtt in", |
||||
"z": "39e98fa5.fea9e8", |
||||
"name": "", |
||||
"topic": "students_201710/devices/ondrej_hruska/up", |
||||
"qos": "2", |
||||
"broker": "98e3cc43.3bd1e", |
||||
"x": 210.5, |
||||
"y": 137, |
||||
"wires": [ |
||||
[ |
||||
"5898399d.a1de7", |
||||
"da550cf8.6db248" |
||||
] |
||||
] |
||||
}, |
||||
{ |
||||
"id": "5898399d.a1de7", |
||||
"type": "debug", |
||||
"z": "39e98fa5.fea9e8", |
||||
"name": "", |
||||
"active": true, |
||||
"console": "false", |
||||
"complete": "payload", |
||||
"x": 611.5, |
||||
"y": 96, |
||||
"wires": [] |
||||
}, |
||||
{ |
||||
"id": "da550cf8.6db248", |
||||
"type": "function", |
||||
"z": "39e98fa5.fea9e8", |
||||
"name": "Extract data", |
||||
"func": "const pld = JSON.parse(msg.payload);\n\nconst bytes = Buffer.from(pld.payload_raw, 'base64');\n\n\nlet resp = {\n time_s: pld.metadata.time,\n time: Math.round((+(new Date(pld.metadata.time)))/1000), // convert to unix\n base64: pld.payload_raw\n};\n\nlet i = 0;\nlet du = () => {\n return bytes[i++]\n};\n\nresp.temp = (du()<<8 | du()) / 100;\nresp.hum = (du()<<8 | du()) / 100;\nresp.press = (85000 + (du() << 8 | du())) / 100;\nresp.gas_r = du() << 24 | du() << 16 | du() << 8 | du();\n\nreturn {payload: resp};\n", |
||||
"outputs": 1, |
||||
"noerr": 0, |
||||
"x": 386.5, |
||||
"y": 224, |
||||
"wires": [ |
||||
[ |
||||
"e983b01f.348d78", |
||||
"697a6626.6df8b8" |
||||
] |
||||
] |
||||
}, |
||||
{ |
||||
"id": "e983b01f.348d78", |
||||
"type": "debug", |
||||
"z": "39e98fa5.fea9e8", |
||||
"name": "", |
||||
"active": true, |
||||
"console": "false", |
||||
"complete": "true", |
||||
"x": 573.5, |
||||
"y": 184, |
||||
"wires": [] |
||||
}, |
||||
{ |
||||
"id": "1daeac40.f9df74", |
||||
"type": "file", |
||||
"z": "39e98fa5.fea9e8", |
||||
"name": "", |
||||
"filename": "/home/ondra/NodeRED/bees.csv", |
||||
"appendNewline": false, |
||||
"createDir": true, |
||||
"overwriteFile": "false", |
||||
"x": 776.5, |
||||
"y": 263, |
||||
"wires": [] |
||||
}, |
||||
{ |
||||
"id": "697a6626.6df8b8", |
||||
"type": "csv", |
||||
"z": "39e98fa5.fea9e8", |
||||
"name": "", |
||||
"sep": ",", |
||||
"hdrin": "", |
||||
"hdrout": "", |
||||
"multi": "one", |
||||
"ret": "\\n", |
||||
"temp": "time,temp,hum,press,gas_r", |
||||
"x": 564.5, |
||||
"y": 264, |
||||
"wires": [ |
||||
[ |
||||
"1daeac40.f9df74" |
||||
] |
||||
] |
||||
}, |
||||
{ |
||||
"id": "98e3cc43.3bd1e", |
||||
"type": "mqtt-broker", |
||||
"z": "", |
||||
"broker": "eu.thethings.network", |
||||
"port": "8883", |
||||
"tls": "", |
||||
"clientid": "", |
||||
"usetls": true, |
||||
"compatmode": true, |
||||
"keepalive": "60", |
||||
"cleansession": true, |
||||
"willTopic": "", |
||||
"willQos": "0", |
||||
"willPayload": "", |
||||
"birthTopic": "", |
||||
"birthQos": "0", |
||||
"birthPayload": "" |
||||
} |
||||
] |
File diff suppressed because one or more lines are too long
@ -1,138 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : gpio.c |
||||
* Description : This file provides code for the configuration |
||||
* of all used GPIO pins. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "gpio.h" |
||||
/* USER CODE BEGIN 0 */ |
||||
|
||||
/* USER CODE END 0 */ |
||||
|
||||
/*----------------------------------------------------------------------------*/ |
||||
/* Configure GPIO */ |
||||
/*----------------------------------------------------------------------------*/ |
||||
/* USER CODE BEGIN 1 */ |
||||
|
||||
/* USER CODE END 1 */ |
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output |
||||
* EVENT_OUT |
||||
* EXTI |
||||
* Free pins are configured automatically as Analog (this feature is enabled through
|
||||
* the Code Generation settings) |
||||
*/ |
||||
void MX_GPIO_Init(void) |
||||
{ |
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct; |
||||
|
||||
/* GPIO Ports Clock Enable */ |
||||
__HAL_RCC_GPIOC_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOH_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOA_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); |
||||
__HAL_RCC_GPIOD_CLK_ENABLE(); |
||||
|
||||
/*Configure GPIO pin : PtPin */ |
||||
GPIO_InitStruct.Pin = B1_Pin; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); |
||||
|
||||
/*Configure GPIO pin : PH1 */ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_1; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
||||
|
||||
/*Configure GPIO pins : PC0 PC1 PC2 PC3
|
||||
PC4 PC5 PC6 PC7
|
||||
PC8 PC9 PC10 PC11
|
||||
PC12 */ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|
||||
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7
|
||||
|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
||||
|GPIO_PIN_12; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
||||
|
||||
/*Configure GPIO pins : PA0 PA1 PA8 PA11
|
||||
PA12 PA15 */ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11
|
||||
|GPIO_PIN_12|GPIO_PIN_15; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||||
|
||||
/*Configure GPIO pins : PB0 PB1 PB2 PB10
|
||||
PB11 PB12 PB13 PB14
|
||||
PB15 PB3 PB4 PB5
|
||||
PB6 PB7 */ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_10
|
||||
|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14
|
||||
|GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5
|
||||
|GPIO_PIN_6|GPIO_PIN_7; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||||
|
||||
/*Configure GPIO pin : PD2 */ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_2; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
||||
|
||||
} |
||||
|
||||
/* USER CODE BEGIN 2 */ |
||||
|
||||
/* USER CODE END 2 */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,78 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : gpio.h |
||||
* Description : This file contains all the functions prototypes for
|
||||
* the gpio
|
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __gpio_H |
||||
#define __gpio_H |
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l0xx_hal.h" |
||||
#include "main.h" |
||||
|
||||
/* USER CODE BEGIN Includes */ |
||||
|
||||
/* USER CODE END Includes */ |
||||
|
||||
/* USER CODE BEGIN Private defines */ |
||||
|
||||
/* USER CODE END Private defines */ |
||||
|
||||
void MX_GPIO_Init(void); |
||||
|
||||
/* USER CODE BEGIN Prototypes */ |
||||
|
||||
/* USER CODE END Prototypes */ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif /*__ pinoutConfig_H */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,149 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : I2C.c |
||||
* Description : This file provides code for the configuration |
||||
* of the I2C instances. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "i2c.h" |
||||
|
||||
#include "gpio.h" |
||||
|
||||
/* USER CODE BEGIN 0 */ |
||||
|
||||
/* USER CODE END 0 */ |
||||
|
||||
I2C_HandleTypeDef hi2c1; |
||||
|
||||
/* I2C1 init function */ |
||||
void MX_I2C1_Init(void) |
||||
{ |
||||
|
||||
hi2c1.Instance = I2C1; |
||||
hi2c1.Init.Timing = 0x00506682; |
||||
hi2c1.Init.OwnAddress1 = 0; |
||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; |
||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; |
||||
hi2c1.Init.OwnAddress2 = 0; |
||||
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; |
||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; |
||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; |
||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
/**Configure Analogue filter
|
||||
*/ |
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
/**Configure Digital filter
|
||||
*/ |
||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
} |
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle) |
||||
{ |
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct; |
||||
if(i2cHandle->Instance==I2C1) |
||||
{ |
||||
/* USER CODE BEGIN I2C1_MspInit 0 */ |
||||
|
||||
/* USER CODE END I2C1_MspInit 0 */ |
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB8 ------> I2C1_SCL |
||||
PB9 ------> I2C1_SDA
|
||||
*/ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; |
||||
GPIO_InitStruct.Pull = GPIO_PULLUP; |
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; |
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
||||
|
||||
/* I2C1 clock enable */ |
||||
__HAL_RCC_I2C1_CLK_ENABLE(); |
||||
/* USER CODE BEGIN I2C1_MspInit 1 */ |
||||
|
||||
/* USER CODE END I2C1_MspInit 1 */ |
||||
} |
||||
} |
||||
|
||||
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle) |
||||
{ |
||||
|
||||
if(i2cHandle->Instance==I2C1) |
||||
{ |
||||
/* USER CODE BEGIN I2C1_MspDeInit 0 */ |
||||
|
||||
/* USER CODE END I2C1_MspDeInit 0 */ |
||||
/* Peripheral clock disable */ |
||||
__HAL_RCC_I2C1_CLK_DISABLE(); |
||||
|
||||
/**I2C1 GPIO Configuration
|
||||
PB8 ------> I2C1_SCL |
||||
PB9 ------> I2C1_SDA
|
||||
*/ |
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9); |
||||
|
||||
/* USER CODE BEGIN I2C1_MspDeInit 1 */ |
||||
|
||||
/* USER CODE END I2C1_MspDeInit 1 */ |
||||
} |
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */ |
||||
|
||||
/* USER CODE END 1 */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,81 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : I2C.h |
||||
* Description : This file provides code for the configuration |
||||
* of the I2C instances. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __i2c_H |
||||
#define __i2c_H |
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l0xx_hal.h" |
||||
#include "main.h" |
||||
|
||||
/* USER CODE BEGIN Includes */ |
||||
|
||||
/* USER CODE END Includes */ |
||||
|
||||
extern I2C_HandleTypeDef hi2c1; |
||||
|
||||
/* USER CODE BEGIN Private defines */ |
||||
|
||||
/* USER CODE END Private defines */ |
||||
|
||||
extern void _Error_Handler(char *, int); |
||||
|
||||
void HW_I2C_Init(void); |
||||
|
||||
/* USER CODE BEGIN Prototypes */ |
||||
|
||||
/* USER CODE END Prototypes */ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif /*__ i2c_H */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,231 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : main.c |
||||
* Description : Main program body |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "main.h" |
||||
#include "stm32l0xx_hal.h" |
||||
#include "i2c.h" |
||||
#include "rtc.h" |
||||
#include "spi.h" |
||||
#include "usart.h" |
||||
#include "gpio.h" |
||||
|
||||
/* USER CODE BEGIN Includes */ |
||||
|
||||
/* USER CODE END Includes */ |
||||
|
||||
/* Private variables ---------------------------------------------------------*/ |
||||
|
||||
/* USER CODE BEGIN PV */ |
||||
/* Private variables ---------------------------------------------------------*/ |
||||
|
||||
/* USER CODE END PV */ |
||||
|
||||
/* Private function prototypes -----------------------------------------------*/ |
||||
void SystemClock_Config(void); |
||||
|
||||
/* USER CODE BEGIN PFP */ |
||||
/* Private function prototypes -----------------------------------------------*/ |
||||
|
||||
/* USER CODE END PFP */ |
||||
|
||||
/* USER CODE BEGIN 0 */ |
||||
|
||||
/* USER CODE END 0 */ |
||||
|
||||
int main(void) |
||||
{ |
||||
|
||||
/* USER CODE BEGIN 1 */ |
||||
|
||||
/* USER CODE END 1 */ |
||||
|
||||
/* MCU Configuration----------------------------------------------------------*/ |
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
||||
HAL_Init(); |
||||
|
||||
/* USER CODE BEGIN Init */ |
||||
|
||||
/* USER CODE END Init */ |
||||
|
||||
/* Configure the system clock */ |
||||
SystemClock_Config(); |
||||
|
||||
/* USER CODE BEGIN SysInit */ |
||||
|
||||
/* USER CODE END SysInit */ |
||||
|
||||
/* Initialize all configured peripherals */ |
||||
MX_GPIO_Init(); |
||||
MX_I2C1_Init(); |
||||
MX_SPI1_Init(); |
||||
MX_USART1_UART_Init(); |
||||
MX_USART2_UART_Init(); |
||||
MX_RTC_Init(); |
||||
|
||||
/* USER CODE BEGIN 2 */ |
||||
|
||||
/* USER CODE END 2 */ |
||||
|
||||
/* Infinite loop */ |
||||
/* USER CODE BEGIN WHILE */ |
||||
while (1) |
||||
{ |
||||
/* USER CODE END WHILE */ |
||||
|
||||
/* USER CODE BEGIN 3 */ |
||||
|
||||
} |
||||
/* USER CODE END 3 */ |
||||
|
||||
} |
||||
|
||||
/** System Clock Configuration
|
||||
*/ |
||||
void SystemClock_Config(void) |
||||
{ |
||||
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct; |
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct; |
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit; |
||||
|
||||
/**Configure the main internal regulator output voltage
|
||||
*/ |
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/ |
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI; |
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
||||
RCC_OscInitStruct.HSICalibrationValue = 16; |
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_3; |
||||
RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2; |
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/ |
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2 |
||||
|RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_RTC; |
||||
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2; |
||||
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; |
||||
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; |
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI; |
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
/**Configure the Systick interrupt time
|
||||
*/ |
||||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
||||
|
||||
/**Configure the Systick
|
||||
*/ |
||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
||||
|
||||
/* SysTick_IRQn interrupt configuration */ |
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
||||
} |
||||
|
||||
/* USER CODE BEGIN 4 */ |
||||
|
||||
/* USER CODE END 4 */ |
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence. |
||||
* @param None |
||||
* @retval None |
||||
*/ |
||||
void _Error_Handler(char * file, int line) |
||||
{ |
||||
/* USER CODE BEGIN Error_Handler_Debug */ |
||||
/* User can add his own implementation to report the HAL error return state */ |
||||
while(1)
|
||||
{ |
||||
} |
||||
/* USER CODE END Error_Handler_Debug */
|
||||
} |
||||
|
||||
#ifdef USE_FULL_ASSERT |
||||
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number |
||||
* where the assert_param error has occurred. |
||||
* @param file: pointer to the source file name |
||||
* @param line: assert_param error line source number |
||||
* @retval None |
||||
*/ |
||||
void assert_failed(uint8_t* file, uint32_t line) |
||||
{ |
||||
/* USER CODE BEGIN 6 */ |
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||||
/* USER CODE END 6 */ |
||||
|
||||
} |
||||
|
||||
#endif |
||||
|
||||
/**
|
||||
* @} |
||||
*/
|
||||
|
||||
/**
|
||||
* @} |
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,114 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : RTC.c |
||||
* Description : This file provides code for the configuration |
||||
* of the RTC instances. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "rtc.h" |
||||
|
||||
/* USER CODE BEGIN 0 */ |
||||
|
||||
/* USER CODE END 0 */ |
||||
|
||||
RTC_HandleTypeDef hrtc; |
||||
|
||||
/* RTC init function */ |
||||
void MX_RTC_Init(void) |
||||
{ |
||||
|
||||
/**Initialize RTC Only
|
||||
*/ |
||||
hrtc.Instance = RTC; |
||||
hrtc.Init.HourFormat = RTC_HOURFORMAT_24; |
||||
hrtc.Init.AsynchPrediv = 127; |
||||
hrtc.Init.SynchPrediv = 255; |
||||
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; |
||||
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE; |
||||
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; |
||||
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; |
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
} |
||||
|
||||
void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle) |
||||
{ |
||||
|
||||
if(rtcHandle->Instance==RTC) |
||||
{ |
||||
/* USER CODE BEGIN RTC_MspInit 0 */ |
||||
|
||||
/* USER CODE END RTC_MspInit 0 */ |
||||
/* RTC clock enable */ |
||||
__HAL_RCC_RTC_ENABLE(); |
||||
/* USER CODE BEGIN RTC_MspInit 1 */ |
||||
|
||||
/* USER CODE END RTC_MspInit 1 */ |
||||
} |
||||
} |
||||
|
||||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle) |
||||
{ |
||||
|
||||
if(rtcHandle->Instance==RTC) |
||||
{ |
||||
/* USER CODE BEGIN RTC_MspDeInit 0 */ |
||||
|
||||
/* USER CODE END RTC_MspDeInit 0 */ |
||||
/* Peripheral clock disable */ |
||||
__HAL_RCC_RTC_DISABLE(); |
||||
/* USER CODE BEGIN RTC_MspDeInit 1 */ |
||||
|
||||
/* USER CODE END RTC_MspDeInit 1 */ |
||||
} |
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */ |
||||
|
||||
/* USER CODE END 1 */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,81 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : RTC.h |
||||
* Description : This file provides code for the configuration |
||||
* of the RTC instances. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __rtc_H |
||||
#define __rtc_H |
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "stm32l0xx_hal.h" |
||||
#include "main.h" |
||||
|
||||
/* USER CODE BEGIN Includes */ |
||||
|
||||
/* USER CODE END Includes */ |
||||
|
||||
extern RTC_HandleTypeDef hrtc; |
||||
|
||||
/* USER CODE BEGIN Private defines */ |
||||
|
||||
/* USER CODE END Private defines */ |
||||
|
||||
extern void _Error_Handler(char *, int); |
||||
|
||||
void MX_RTC_Init(void); |
||||
|
||||
/* USER CODE BEGIN Prototypes */ |
||||
|
||||
/* USER CODE END Prototypes */ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif /*__ rtc_H */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,142 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : SPI.c |
||||
* Description : This file provides code for the configuration |
||||
* of the SPI instances. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
|
||||
/* Includes ------------------------------------------------------------------*/ |
||||
#include "spi.h" |
||||
|
||||
#include "gpio.h" |
||||
|
||||
/* USER CODE BEGIN 0 */ |
||||
|
||||
/* USER CODE END 0 */ |
||||
|
||||
SPI_HandleTypeDef hspi1; |
||||
|
||||
/* SPI1 init function */ |
||||
void MX_SPI1_Init(void) |
||||
{ |
||||
|
||||
hspi1.Instance = SPI1; |
||||
hspi1.Init.Mode = SPI_MODE_MASTER; |
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES; |
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; |
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||||
hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT; |
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; |
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||||
hspi1.Init.CRCPolynomial = 7; |
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK) |
||||
{ |
||||
_Error_Handler(__FILE__, __LINE__); |
||||
} |
||||
|
||||
} |
||||
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) |
||||
{ |
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct; |
||||
if(spiHandle->Instance==SPI1) |
||||
{ |
||||
/* USER CODE BEGIN SPI1_MspInit 0 */ |
||||
|
||||
/* USER CODE END SPI1_MspInit 0 */ |
||||
/* SPI1 clock enable */ |
||||
__HAL_RCC_SPI1_CLK_ENABLE(); |
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA4 ------> SPI1_NSS |
||||
PA5 ------> SPI1_SCK |
||||
PA6 ------> SPI1_MISO |
||||
PA7 ------> SPI1_MOSI
|
||||
*/ |
||||
GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; |
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||||
GPIO_InitStruct.Pull = GPIO_NOPULL; |
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
||||
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1; |
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||||
|
||||
/* USER CODE BEGIN SPI1_MspInit 1 */ |
||||
|
||||
/* USER CODE END SPI1_MspInit 1 */ |
||||
} |
||||
} |
||||
|
||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) |
||||
{ |
||||
|
||||
if(spiHandle->Instance==SPI1) |
||||
{ |
||||
/* USER CODE BEGIN SPI1_MspDeInit 0 */ |
||||
|
||||
/* USER CODE END SPI1_MspDeInit 0 */ |
||||
/* Peripheral clock disable */ |
||||
__HAL_RCC_SPI1_CLK_DISABLE(); |
||||
|
||||
/**SPI1 GPIO Configuration
|
||||
PA4 ------> SPI1_NSS |
||||
PA5 ------> SPI1_SCK |
||||
PA6 ------> SPI1_MISO |
||||
PA7 ------> SPI1_MOSI
|
||||
*/ |
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); |
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */ |
||||
|
||||
/* USER CODE END SPI1_MspDeInit 1 */ |
||||
} |
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */ |
||||
|
||||
/* USER CODE END 1 */ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/**
|
||||
* @} |
||||
*/ |
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
@ -1,81 +0,0 @@ |
||||
/**
|
||||
****************************************************************************** |
||||
* File Name : SPI.h |
||||
* Description : This file provides code for the configuration |
||||
* of the SPI instances. |
||||
****************************************************************************** |
||||
** This notice applies to any and all portions of this file |
||||
* that are not between comment pairs USER CODE BEGIN and |
||||
* USER CODE END. Other portions of this file, whether
|
||||
* inserted by the user or by software development tools |
||||
* are owned by their respective copyright owners. |
||||
* |
||||
* COPYRIGHT(c) 2017 STMicroelectronics |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without modification, |
||||
* are permitted provided that the following conditions are met: |
||||
* 1. Redistributions of source code must retain the above copyright notice, |
||||
* this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, |
||||
* this list of conditions and the following disclaimer in the documentation |
||||
* and/or other materials provided with the distribution. |
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
||||
* may be used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************** |
||||
*/ |
||||
/* Define to prevent recursive inclusion -------------------------------------*/ |
||||
#ifndef __spi_H |
||||
#define __spi_H |
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
< |