Question on MC13213 PORT define

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

Question on MC13213 PORT define

Jump to solution
509 Views
rexzhou
Contributor I

Hello,

 

I am a newer on freescale 8-bit MCU. Now I am in the process of adding 1-wire sensor communication on a Beekit generated project. The one wire is connected with Port A pin0 of MC13213 SRB demo board. While I assign the port which I will use to communicate with 1-wire, I have a question about the definition of the port in mc9s08gb60.h file.

 

For example when define the data register in port A @ 0x00000000, the codes are:

 

/*** PTAD - Port A Data Register; 0x00000000 ***/typedef union {  byte Byte;  struct {    byte PTAD0       :1;      /* Port A Data Register Bit 0 */    byte PTAD1       :1;      /* Port A Data Register Bit 1 */    byte PTAD2       :1;      /* Port A Data Register Bit 2 */    byte PTAD3       :1;      /* Port A Data Register Bit 3 */    byte PTAD4       :1;      /* Port A Data Register Bit 4 */    byte PTAD5       :1;      /* Port A Data Register Bit 5 */    byte PTAD6       :1;      /* Port A Data Register Bit 6 */    byte PTAD7       :1;      /* Port A Data Register Bit 7 */  } Bits;} PTADSTR;extern volatile PTADSTR _PTAD @0x00000000;#define PTAD                            _PTAD.Byte#define PTAD_PTAD0                      _PTAD.Bits.PTAD0#define PTAD_PTAD1                      _PTAD.Bits.PTAD1#define PTAD_PTAD2                      _PTAD.Bits.PTAD2#define PTAD_PTAD3                      _PTAD.Bits.PTAD3#define PTAD_PTAD4                      _PTAD.Bits.PTAD4#define PTAD_PTAD5                      _PTAD.Bits.PTAD5#define PTAD_PTAD6                      _PTAD.Bits.PTAD6#define PTAD_PTAD7                      _PTAD.Bits.PTAD7

 

My question is that the code defined the data register from bit 0 to 7 using PTAD_PTAD0 to PTAD_PTAD7. But it seems all of them are pointing at the same address @ 0x00000000. Why not just define only one data register and use a offset value to find the others? Also, while define the Bits structure, the type for PTAD0 to PTAD7 is in byte type. Is there any reason to define them as byte? Thanks


Labels (1)
0 Kudos
1 Solution
321 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

Don't confuse bits and bytes.  The code that you have shown defines a union between a byte and a bit field.  Each element of the bit field represents an individual bit within the 8-bit register at address 0x0000.  The macros are then used to simplify the appearance of the code.

 

The macro associated with _PTAD.Byte is used when all bits of the register need to be simultaneously written or read.

 

You will notice that bit mask values are also defined in the file.  These may be used in lieu of the bit field, at the expense of code of more complex appearance.

 

For the one-wire interface, there are time critical elements within the "bit-banged" code, especially for the processing of each bit within a sequence.  I have previously chosen to use inline assembly code to provide very tight control of the timing.  For the one-wire pin manipulation, I therefore directly used assembler.

 

Note that, during the time critical periods of the one-wire operation, all interrupts need to be globally inhibited so that the timing cannot be affected.  I am not sure whether this is compatible with Zigbee operation.

 

Regards,

Mac

 

View solution in original post

0 Kudos
1 Reply
322 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

Don't confuse bits and bytes.  The code that you have shown defines a union between a byte and a bit field.  Each element of the bit field represents an individual bit within the 8-bit register at address 0x0000.  The macros are then used to simplify the appearance of the code.

 

The macro associated with _PTAD.Byte is used when all bits of the register need to be simultaneously written or read.

 

You will notice that bit mask values are also defined in the file.  These may be used in lieu of the bit field, at the expense of code of more complex appearance.

 

For the one-wire interface, there are time critical elements within the "bit-banged" code, especially for the processing of each bit within a sequence.  I have previously chosen to use inline assembly code to provide very tight control of the timing.  For the one-wire pin manipulation, I therefore directly used assembler.

 

Note that, during the time critical periods of the one-wire operation, all interrupts need to be globally inhibited so that the timing cannot be affected.  I am not sure whether this is compatible with Zigbee operation.

 

Regards,

Mac

 

0 Kudos