Monitor backup battery (VBAT) using LVD

Hi, I want to monitor the backup battery voltage (VBAT) on an RA6M5 with FSP-5.1. I added the LVD stack to the project but I see BSP_FEATURE_LVD_HAS_EXT_MONITOR is disabled everywhere.
1. How can I enable it?
2. Also, should I select Monitor Number 1 or 2?


  • Hello,

    The LVD module can only monitor the VCC pin - not VBATT pin.

    The battery backup function should be used after the voltage monitor 0 reset is enabled (OFS1.LVDAS bit is 0).
    Voltage monitor 0 level should be higher than VBATT switch level.

    The LVD module only supports configuring voltage monitor 1 and voltage monitor 2. Voltage monitor 0 can be configured by setting the appropriate bits in the OFS1 register. This means that voltage monitor 0 settings cannot be changed at runtime.


  • Hi.
    Thanks for the information.
    - My voltage monitor 0 reset is enabled (attached).
    - The voltage monitor 0 level was already 2.8V and the level for V(BATTSW) is 2.7V, so it is higher.

    According to my understanding of the section "Battery Backup Function" in the manual, I must:
    - set bit0 of VBATTMNSEL to enable VBATT low voltage detect function.
    - I check if the battery is low by reading bit0 of VBATTMON.
    - I leave VBTICTLR unchanged (bits VCH0INEN=0, VCH1INEN=0, VCH2INEN=1). I already use input capture on the RTC (via P404) and it works.

    1.  I currently try to set VBATTMNSEL with the code below, but it gets stuck on the 1st while loop and never actually sets the bit0.  What is the trick to set it?

    2.  I cannot find a setting for VBATTMNSEL in the configuration.xml file or FSP API, is this correct?

    3. Only R_SYSTEM->VBTICTLR is set up in R_BSP_Init_RTC() and bsp_vbatt_init(), and not the other related Battery Backup registers like VBATTMNSEL. Is this a bug?

    4.  I don't see the battery-low interrupt (VBTLVDICR) in the configuration.xml view. Do I also need to set this up manually like VBATTMNSEL?

    5. Do you have an example code for low-battery detection as I don't see it in the example projects for RA6M5?


    bool b_battbak_init(void)
      //R_SYSTEM->VBTICTLR |= (uint8_t) (1U << vbatt_index);
      R_SYSTEM->VBATTMNSELR_b.VBATTMNSEL = 1; //VBATT Low Voltage Detect Function Select Bit
      while(R_SYSTEM->VBATTMNSELR_b.VBATTMNSEL != 1) { };
      R_SYSTEM->VBTLVDICR_b.VBTLVDIE = 1; //VBATT Pin Low Voltage Detect Enable Bit
      while(R_SYSTEM->VBTLVDICR_b.VBTLVDIE != 1) { };
      return true;

  • Hello,

    Please try this to change the VBATTMNSEL bit. The PCR3 bit needs to be 1 to enable write.

        //Set the PRCR.PRC3 bit to 1 (write enabled)
        R_SYSTEM->PRCR = 0xA508 ;
        R_SYSTEM->VBATTMNSELR_b.VBATTMNSEL = 1; //VBATT Low Voltage Detect Function Select Bit
        //Set the PRCR.PRC3 bit to 0 (write disabled)
        R_SYSTEM->PRCR = 0xA500 ;

    There is no VBTLVDICR register on RA6M5 because the Battery Backup function does not support VBATT pin low voltage detection as other devices do (for example RA4M1).

    The Battery Backup Function on RA6M5 supports only:

    - Battery power supply switch
    - Backup registers
    - Time capture pin detection

    Do you want to monitor VBATT pin or just switch to VBATT when VCC drops ? 

  • Hi.  To answer your 2 questions:

    Do you want to monitor VBATT pin?

    Yes, and these sentences in the manual led me to believe it is possible:

    VBATTMNSELR is the register which controls VBATT low voltage detect function.
    VBATTMONR is the register that can check VBATT voltage level when VBATTMNSELR.VBATTMNSEL = 1 and also VCC is supplied.

    Or just switch to VBATT when VCC drops? 

    Yes, and this is already working because RTC-Capture transitions are caught with Vcc off (0V).


    Does this mean the manual is wrong?


    I tested your code "R_SYSTEM->PRCR = 0xA508" and I can now set the bit R_SYSTEM->VBATTMNSELR_b.VBATTMNSEL, but it doesn't seem to detect the voltage of the battery because I adjust it down to 2.3V and R_SYSTEM->VBATTMONR_b.VBATTMON still doesn't get set.


  • On RA6M5 you can read the VBATTMONR register to check if VBATT is lower than Vbattldet but when it drops under this level, no interrupt will be generated. And this level is not changable, it is 1.9V (typical value).

    This is different than VBATT pin low voltage detection which is supported by other devices with VBTLVDICR register (for example RA4M1). On these devices an interrupt can be generated and the voltage level can be selected.

    Now I think you confuse VDETBATT with Vbattldet.

    The VBATTMON bit will be set to 1 when VBATT < Vbattldet = 1.9V.

    VDETBATT indicates the threshold level of the power supply change between the VCC pin and the VBATT pin.

    Also voltage monitor 0 level should be higher than VBATT switch level (VDETBATT) which is by default because it is 2.80, 2.87 or 2.94V and VDETBATT max value is 2.70.

    So these are 3 different voltage levels.

    I hope it clears up.

  • Thank you for explaining the difference between VDETBATT and Vbattldet.

    So just to confirm:

    Once I set "R_SYSTEM->VBATTMNSELR_b.VBATTMNSEL" I should be able to detect a low (<1.9V) battery level by reading VBATTMON? (see code below)

    I tested this earlier by connecting a variable supply to the Vbat pin and it didn't set VBATTMON.  I will retest.

    bool b_battbak_islow(void)


  • Yes, this is the idea. The following graphs may explain it better:

    Also make sure the VBATT is within the allowable range:

  • Thank you for the help.  I tested it now and it works.