Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C language question: How to set up 32 bit register?

Status
Not open for further replies.

MagicSpark

Newbie level 5
Joined
Oct 17, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,370
I need to configure device which is controlled by 32 bit register, located at the address 0x5000 for example I am trying to figure out what is the best approach to set the 32-bit register in ANSI C language.

First approach is to set each byte separately

#define PLLCONFIG0 0x5000
#define PLLCONFIG1 0x5001
#define PLLCONFIG2 0x5002
#define PLLCONFIG3 0x5003

Then in the program set each byte separately, for example:
PLLCONFIG0 = 0xFA ;
PLLCONFIG1 = 0x08 ;
PLLCONFIG2 = 0xF0 ;
PLLCONFIG3 = 0xAE ;

The problem with this approach is that if certain parameter is 11 bits wide,
for example from 8 to 18 bit, then one must split value of the parameter and
figure out values for separate bytes.


The second approach is to try to set value of the register at once as 32 bit long value:

unsigned long* pPLLConfig = (unsigned long*) 0x5000 ;

*pPLLConfig = 0xAEF008FA ;


Please advise what approach is better. If you know where can I find C examples
for similar multibytes register configuration, please let me know.

Thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top