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 http://www.EmbeddedRelated.com
How to configure digital output in Renesas RH850/FIL Micrcontroller ?
Started by ●May 28, 2015
Reply by ●May 28, 20152015-05-28
On Thu, 28 May 2015 18:31:49 -0500, learn wrote:> 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 ?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<uint16_t *>(0xffc103c8) &= 0xdfffffff; except that you're being loosey-goosey with the standard, so you may need to use *reinterpret_cast<uint16_t *>(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
Reply by ●May 29, 20152015-05-29
>On Thu, 28 May 2015 18:31:49 -0500, learn wrote: > >> 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 ? > >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<uint16_t *>(0xffc103c8) &= 0xdfffffff; > >except that you're being loosey-goosey with the standard, so you may need>to use > >*reinterpret_cast<uint16_t *>(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.comIt'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 http://www.EmbeddedRelated.com
Reply by ●May 29, 20152015-05-29
On 29/05/15 15:24, learn wrote:>> On Thu, 28 May 2015 18:31:49 -0500, learn wrote: >> >>> 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 ? >> >> 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<uint16_t *>(0xffc103c8) &= 0xdfffffff; >> >> except that you're being loosey-goosey with the standard, so you may need > >> to use >> >> *reinterpret_cast<uint16_t *>(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 > > > 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 > ?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 << 14); (The fact that Tim wrote "0xdfffffff", which is for bit 29 in a 32-bit register rather than bit 14 in a 16-bit register, demonstrates why it is so much better if you can use device-specific header files with these registers predefined!)
Reply by ●May 29, 20152015-05-29
>On 29/05/15 15:24, learn wrote: >>> On Thu, 28 May 2015 18:31:49 -0500, learn wrote: >>> >>>> I need to configure pin AP0_14 for digital output. To achieve thisI>>>> 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 usingthe>>>> physical address ? >>> >>> Homework? >>> >>> First, before you read any more, your tools should have come withheader>> >>> files that give you macro files, structure definitions, or somethingto>>> 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 correctbut>> >>> 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<uint16_t *>(0xffc103c8) &= 0xdfffffff; >>> >>> except that you're being loosey-goosey with the standard, so you may >need >> >>> to use >>> >>> *reinterpret_cast<uint16_t *>(0xffc103c8) &= 0xdfffffff; >>> >>> A _far far_ better way to do it is to make a bitmapped structure, mapit>> >>> 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 >> >> >> 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 >> ? > >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 << 14); > > >(The fact that Tim wrote "0xdfffffff", which is for bit 29 in a 32-bit >register rather than bit 14 in a 16-bit register, demonstrates why it is >so much better if you can use device-specific header files with these >registers predefined!)OK. Initially, I had 32-bit value on the right hand side. Switching to 16-bit worked fine. Thanks very much. --------------------------------------- Posted through http://www.EmbeddedRelated.com







