Skip to content
Snippets Groups Projects
Commit f56730ba authored by Federico's avatar Federico
Browse files

Added low voltage detection to tempsensor bsp

parent b01da902
Branches
Tags
No related merge requests found
...@@ -110,6 +110,12 @@ void showNumber(float number) ...@@ -110,6 +110,12 @@ void showNumber(float number)
} }
} }
void showLowVoltageIndicator()
{
static const char bat[]={0x7c,0x77,0x78,0x0}; //"bAt "
memcpy(digits,bat,4);
}
// //
// AD7789 driver // AD7789 driver
// //
...@@ -162,6 +168,22 @@ unsigned int readAdcValue() ...@@ -162,6 +168,22 @@ unsigned int readAdcValue()
return result; return result;
} }
//
// PVD driver
//
static void configureLowVoltageDetect()
{
PWR->CR |= PWR_CR_PVDE //Low voltage detect enabled
| PWR_CR_PLS_1
| PWR_CR_PLS_0; //2.5V threshold
}
bool lowVoltageCheck()
{
return (PWR->CSR & PWR_CSR_PVDO) ? false : true;
}
// //
// class NonVolatileStorage // class NonVolatileStorage
// //
...@@ -247,7 +269,7 @@ void IRQbspInit() ...@@ -247,7 +269,7 @@ void IRQbspInit()
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN |
RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN |
RCC_APB2ENR_AFIOEN | RCC_APB2ENR_SPI1EN; RCC_APB2ENR_AFIOEN | RCC_APB2ENR_SPI1EN;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; RCC->APB1ENR |= RCC_APB1ENR_TIM3EN | RCC_APB1ENR_PWREN;
RCC_SYNC(); RCC_SYNC();
//Board has no JTAG nor SWD, and those pins are used //Board has no JTAG nor SWD, and those pins are used
...@@ -267,6 +289,7 @@ void IRQbspInit() ...@@ -267,6 +289,7 @@ void IRQbspInit()
GPIOD->CRL=0x22222222; //PD0 and PD1 all out GPIOD->CRL=0x22222222; //PD0 and PD1 all out
initAdc(); initAdc();
configureLowVoltageDetect();
DefaultConsole::instance().IRQset(intrusive_ref_ptr<Device>( DefaultConsole::instance().IRQset(intrusive_ref_ptr<Device>(
new STM32Serial(defaultSerial,defaultSerialSpeed, new STM32Serial(defaultSerial,defaultSerialSpeed,
......
...@@ -48,6 +48,11 @@ void clearDisplay(); ...@@ -48,6 +48,11 @@ void clearDisplay();
*/ */
void showNumber(float number); void showNumber(float number);
/**
* Show the word "bAt" on the LED display
*/
void showLowVoltageIndicator();
typedef Gpio<GPIOA_BASE,4> cs; ///< For low-level SPI access typedef Gpio<GPIOA_BASE,4> cs; ///< For low-level SPI access
/** /**
...@@ -70,6 +75,11 @@ unsigned char readStatusReg(); ...@@ -70,6 +75,11 @@ unsigned char readStatusReg();
*/ */
unsigned int readAdcValue(); unsigned int readAdcValue();
/**
* \return true if the supply voltege is high enough
*/
bool lowVoltageCheck();
/** /**
* This class allows to store non volatile data into the last FLASH page * This class allows to store non volatile data into the last FLASH page
* of the microcontroller. * of the microcontroller.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment