How to configure digital output in Renesas RH850/FIL Micrcontroller ?
May 28, 2015 4 Replies
L
learn
I need to configure pin AP0_14 for digital output. To achieve this I need to write 0 to bit 14 of 16-bit Port Mode Register.
The physical address of this register is: 0xFFC103C8
What should be the exact statement to write to this register using the physical address ?
--------------------------------------- Posted through
formatting link
Didn't find your answer? Ask the community — no account required.
T
Tim Wescott
Homework?
First, before you read any more, your tools should have come with header files that give you macro files, structure definitions, or something to do this. You should find them and use them.
If that doesn't float your boat, read on.
There are lots and lots of ways to do this, ranging from the correct but ugly, through pretty but wrong, and back to correct, but pretty this time. Which "should" are you interested in?
Ugly but effective (I think -- try this) in C is
*(uint16_t *)(0xffc103c8) &= 0xdfffffff;
In C++ that'll give you compiler warnings, so you change it to
*static_cast(0xffc103c8) &= 0xdfffffff;
except that you're being loosey-goosey with the standard, so you may need to use
*reinterpret_cast(0xffc103c8) &= 0xdfffffff;
A _far far_ better way to do it is to make a bitmapped structure, map it to the correct memory location in your linker file or in an assembly file, and then change the one bit explicitly. Assuming that the bit enables the gzorgle, you'll end up with something like
SOMETHING_OR_OTHER.PMR.bits.GZORGLE_EN = 0;
Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
L
learn
It's not homework. I need to toggle output pin to measure task rate. Thank you for the solution. I'll try it. Don't I need a volatile keyword ?
--------------------------------------- Posted through
formatting link
D
David Brown
Yes, you need "volatile" - so you would have something like this:
*(volatile uint16_t *)(0xffc103c8) &= 0xbfff;
or, better,
*(volatile uint16_t *)(0xffc103c8) &= ~0x4000;
or
*(volatile uint16_t *)(0xffc103c8) &= ~(1u
L
learn
I
the
header
to
but
it
OK. Initially, I had 32-bit value on the right hand side. Switching to
16-bit worked fine.
Thanks very much.
--------------------------------------- Posted through
formatting link
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.