MCF52259 - PORTTHx / FB_Dx control registers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MCF52259 - PORTTHx / FB_Dx control registers

Jump to solution
1,166 Views
FridgeFreezer
Senior Contributor I

Before my brain melts, can anyone clarify the port/pin registers for this?

 

As far as I can make out:

FB_D0 = PTH6 = Pin51
FB_D1 = PTH7 = Pin50
FB_D2 = PTH0 = Pin47
FB_D3 = PTH1 = Pin46

FB_D4 = PTH2 = Pin1
FB_D5 = PTH3 = Pin140
FB_D6 = PTH4 = Pin139
FB_D7 = PTH5 = Pin138

 

And the config registers are organised in differing orders:

 

MCF_GPIO_PTHPAR_ is in FB_Dx order where FB_D0 is BIT0&1 and FB_D7 is BIT14&15

MCF_GPIO_DDRTH_ is in PTHx order where DDRTH0 is BIT0 and DDRTH7 is BIT7

MCF_GPIO_SETTH_ is in PTHx order where SETTH0 is BIT0 and SETTH7 is BIT7

MCF_GPIO_CLRTH_ is in PTHx order where CLRTH0 is BIT0 and CLRTH7 is BIT7

 

So the question is, say I want to set pin 138 as an output and toggle it, do I set PTHPAR7 = GPIO to assign it but then set DDRTH5 to make it an output, and write MCF_GPIO_PORTTH ^= MCF_GPIO_PORTTH_PORTTH5 to toggle it.

Labels (1)
0 Kudos
Reply
1 Solution
443 Views
FridgeFreezer
Senior Contributor I

This issue has come back to bite me again, the MCF52259 reference manual states that PORTTH is at IPSBAR+0x10_0003 (well, it actually states it's "POTRTH" as someone seems to have had a bad day with the spelling :smileyindifferent:

 

However, as I am trying to read the pins as inputs the manual states I should read the pin data/set data register PORTnP/SETn which it then calls PORTTH/SETTH, with an address of IPSBAR+0x10_0033

 

The pin data/set data register "SetTF" is indeed defined at IPSBAR+0x10_0033, but if you read MCF_GPIO_PORTTH you are reading the data output register and in fact need to (counter-intuitively) read the MCF_GPIO_SETTH register.

 

IJust thought I'd tag this on the end in case someone else finds it useful.

View solution in original post

0 Kudos
Reply
2 Replies
443 Views
FridgeFreezer
Senior Contributor I

A bit more fiddling today has found that the registers are assigned relative to PORTTH, so if I want to set pin 138 as an output and toggle it, I set PTHPAR5 = GPIO to assign it and set DDRTH5 to make it an output, and write MCF_GPIO_PORTTH ^= MCF_GPIO_PORTTH_PORTTH5 to toggle it.

 

However, the header files for the micro seem to be the wrong way round. PTH2 & 3 (FB4 & 5) are I2C ports, yet the bit field for the port includes:

MCF_GPIO_PTHPAR_MB_D5_SCL1 (0x800) which sets PTH5 to its secondary function as CANRX.

 

Confused yet? :smileysurprised:

0 Kudos
Reply
444 Views
FridgeFreezer
Senior Contributor I

This issue has come back to bite me again, the MCF52259 reference manual states that PORTTH is at IPSBAR+0x10_0003 (well, it actually states it's "POTRTH" as someone seems to have had a bad day with the spelling :smileyindifferent:

 

However, as I am trying to read the pins as inputs the manual states I should read the pin data/set data register PORTnP/SETn which it then calls PORTTH/SETTH, with an address of IPSBAR+0x10_0033

 

The pin data/set data register "SetTF" is indeed defined at IPSBAR+0x10_0033, but if you read MCF_GPIO_PORTTH you are reading the data output register and in fact need to (counter-intuitively) read the MCF_GPIO_SETTH register.

 

IJust thought I'd tag this on the end in case someone else finds it useful.

0 Kudos
Reply