| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

I2C_Master_w_Sensor_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : I2C_Master_w_Sensor_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the I2C master functionality using the environmental sensor
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
176 /* Includes ------------------------------------------------------------------*/
177 #include "BlueNRG1.h"
178 #include <stdio.h>
179 #include "BlueNRG1_conf.h"
180 #include "SDK_EVAL_Config.h"
181 #include "LPS25HB_hal.h"
182
195 /* Private typedef -----------------------------------------------------------*/
196 /* Private define ------------------------------------------------------------*/
197 #define SYST_CLOCK 16000000
198
199 /* Private macro -------------------------------------------------------------*/
200 /* Private variables ---------------------------------------------------------*/
201 volatile uint32_t lSystickCounter=0;
202
203 /* Private function prototypes -----------------------------------------------*/
204 void SdkDelayMs(volatile uint32_t lTimeMs);
205
206 /* Private functions ---------------------------------------------------------*/
207
208
214 int main(void)
215 {
216 float pressure, temperature;
217 uint8_t tmpreg;
218
219 /* System initialization function */
220 SystemInit();
221
222 /* Identify BlueNRG1 platform */
223 SdkEvalIdentification();
224
225 /* UART initialization */
226 SdkEvalComUartInit(UART_BAUDRATE);
227
228 /* LED initialization */
229 SdkEvalLedInit(LED1);
230
231 /* LPS25HB initialization */
232 PRESSURE_DrvTypeDef* xLPS25HBDrv = &LPS25HBDrv;
233 PRESSURE_InitTypeDef InitStructure;
234 InitStructure.OutputDataRate = LPS25HB_ODR_1Hz;
235 InitStructure.BlockDataUpdate = LPS25HB_BDU_READ;
236 InitStructure.DiffEnable = LPS25HB_DIFF_ENABLE;
237 InitStructure.SPIMode = LPS25HB_SPI_SIM_3W;
238 InitStructure.PressureResolution = LPS25HB_P_RES_AVG_32;
239 InitStructure.TemperatureResolution = LPS25HB_T_RES_AVG_16;
240 xLPS25HBDrv->Init(&InitStructure);
241
242 /* Configure SysTick to generate interrupt */
243 SysTick_Config(SYST_CLOCK/1000 - 1);
244
245 /* Infinite loop */
246 while(1) {
247
248 /* Polling of IRQ_STATUS register */
249 LPS25HB_IO_Read(&tmpreg, LPS25HB_ADDRESS_LOW, LPS25HB_STATUS_REG_ADDR, 1);
250
251 if( (tmpreg&0x03) == 0x03) {
252 /* Get pressure and temperature data */
253 xLPS25HBDrv->GetPressure(&pressure);
254 xLPS25HBDrv->GetTemperature(&temperature);
255 printf("PRESSURE: %.3f mbar TEMP: %.2f 'C\r\n", pressure, temperature);
256 SdkEvalLedToggle(LED1);
257 }
258 SdkDelayMs(200);
259 }
260 }
261
262
268 void SdkDelayMs(volatile uint32_t lTimeMs)
269 {
270 uint32_t nWaitPeriod = ~lSystickCounter;
271
272 if(nWaitPeriod<lTimeMs)
273 {
274 while( lSystickCounter != 0xFFFFFFFF);
275 nWaitPeriod = lTimeMs-nWaitPeriod;
276 }
277 else
278 nWaitPeriod = lTimeMs+ ~nWaitPeriod;
279
280 while( lSystickCounter != nWaitPeriod ) ;
281
282 }
283
284
285 #ifdef USE_FULL_ASSERT
286
293 void assert_failed(uint8_t* file, uint32_t line)
294 {
295 /* User can add his own implementation to report the file name and line number,
296 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
297
298 /* Infinite loop */
299 while (1)
300 {
301 }
302 }
303
304 #endif
305
318 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
SdkDelayMs
void SdkDelayMs(volatile uint32_t lTimeMs)
Delay function.
Definition: I2C_Master_w_Sensor_main.c:268
lSystickCounter
volatile uint32_t lSystickCounter
Definition: I2C_Master_w_Sensor_main.c:201
main
int main(void)
Main program code.
Definition: I2C_Master_w_Sensor_main.c:214
SYST_CLOCK
#define SYST_CLOCK
Definition: I2C_Master_w_Sensor_main.c:197
UART_BAUDRATE
#define UART_BAUDRATE
Definition: ADC_PDM_main.c:225