Author Topic: VBAT Detection  (Read 3615 times)

Offline AlexS

  • Newbie
  • *
  • Posts: 46
    • View Profile
VBAT Detection
« on: January 04, 2019, 04:40:02 PM »
Hi,

Unfortunately, when we designed our K66-based board, we didn't expect for the MCU designers to not factor in a way of detecting whether VBAT is present or not, without triggering a bus fault when trying to access the RTC registers. Mark, I've seen one of your posts on the NXP technical community mentioning a way to use DMA to detect whether VBAT/RTC are active or not. Do you have some example code on the subject by any chance or maybe suggest an alternative solution?

Thanks,
Alex

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: VBAT Detection
« Reply #1 on: January 04, 2019, 09:29:17 PM »
Hi Alex

I hadn't tried this but it was the only method that I could think of that would be easy to recover from if the access failed.

This is the code that I suggest:


Code: [Select]
        {
            unsigned long ulRegCopy;
            POWER_UP_ATOMIC(6, RTC);                                     // ensure the RTC is powered
            if (DMA_ERROR_OCCURRED == fnConfigDMA_buffer(4, 0, sizeof(ulRegCopy), (void *)RTC_BLOCK, &ulRegCopy, (DMA_DIRECTION_INPUT | DMA_LONG_WORDS | DMA_SINGLE_CYCLE | DMA_FIXED_ADDRESSES | DMA_SW_TRIGGER_WAIT_TERMINATION), 0, 0)) { // configure the transfer, start and wait for termination
                // RTC cannot be accessed - probably due to missing VBAT voltage
                //
            }
            else {
                // ulRegCopy has the present RTC_TSR content, meaning that the RTC could be accessed
            }
        }

This is using DMA channel 4 for the test (the channel used being configurable).

I have however just added a return value to fnConfigDMA_buffer() as well as a check for DMA errors during the copy. You can get the updated kinetis.h (with prototype) and kinetis_DMA.h from the repository (I just checked them in).

Tell me whether the solution works for your requirements.

Good luck

Regards

Mark


P.S. Could you give me a link to the NXP forum post since I couldn't find it when I just searched?
« Last Edit: January 08, 2019, 01:58:03 AM by mark »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: VBAT Detection
« Reply #2 on: January 08, 2019, 01:57:46 AM »
Alex

I had the chance to test this on  FRDM-K66F today and it worked as hoped ;-)

Regards

Mark


Offline AlexS

  • Newbie
  • *
  • Posts: 46
    • View Profile
Re: VBAT Detection
« Reply #3 on: January 14, 2019, 03:57:30 PM »
Hi Mark,

Thanks a lot for your reply! I also tested the code on our custom board and it worked.

This is where I found the original mention about DMA: https://community.nxp.com/thread/466102#comment-1020093

Regards,
Alex