Trying to understand registers on MSP430G2553

Thread Starter

StrongPenguin

Joined Jun 9, 2018
307
@ArakelTheDragon I think I somewhat got a hold on the WTD. Following the schematic in the Datasheet/Guide helped a lot with this.

@MrChips I'm trying to decode your struct, and I have a couple of questions.

You write
C:
#pragma LOCATION(P1IN_bit,  0x0020);
#pragma LOCATION(P1OUT_bit, 0x0021);
Why is it necessary to store these variables in a pragma location?
Where is this 0x0020? If I look at the memory map on page 25 in the user guide, I land on the 8 Bit Peripheral Module section :confused:
 

MrChips

Joined Oct 2, 2009
35,018
#pragma is simply a fancy word to the compiler to mean "hello", "hi", "alert", "watch out, here I come".

It alerts the compiler that you are going to say something out of the ordinary.

LOCATION ( identifier, address) is the CCS way of specifying a memory address to be assigned to the identifier.

IAR uses @address.

Hence LOCATION (xyz, 0x0020) says to use location 0x0020 when referring to xyz.

Address 0x0020 is the hardware address of P1IN
Address 0x0021 is the hardware address of P1OUT

When I get to my workstation I will provide you with the doc that shows all the hardware address assignments.
CCS has not made this as straight forward as what they did in IAR. In any case using CCS should still do the job fine.
 

MrChips

Joined Oct 2, 2009
35,018
The hardware names and assigned addresses are in a file called msp430g2553.cmd

You can go to your CCS Project Explorer window and look for Includes folder.

Expand the Includes folder by either clicking on > or double click on Includes.
Expand C:/ti/ccsv6/ccs_base/msp430/include or something similar.

Double click on msp430g2553.cmd

Or you can search through your hard drive file system for the same file using your OS.

This is how it is saved on my computer:

C:/ti/ccsv6/ccs_base/msp430/include/msp430g2553.cmd

This is one of the things that makes code "portable". You can expect to be able to go to a different chip and your code should still run even if the hardware modules are at different addresses.
 

Thread Starter

StrongPenguin

Joined Jun 9, 2018
307
@MrChips Thanks for clearing that up. I found the .cmd file in CCS, and also a (thin) guide on how to use the LOCATION on TI's MSP wiki. I can see my C programming skills could be better, so I will focus a bit on that for the next days/weeks/decades. Thanks for all the help, much appreciated.
 

ArakelTheDragon

Joined Nov 18, 2016
1,366
@MrChips Thanks for clearing that up. I found the .cmd file in CCS, and also a (thin) guide on how to use the LOCATION on TI's MSP wiki. I can see my C programming skills could be better, so I will focus a bit on that for the next days/weeks/decades. Thanks for all the help, much appreciated.
It depends how active you are, it does not needs to be decades.

Try the "Kernighan and Ritchie book 2". Also the CCS Info forum is very helpful, in particular Ttelmah", "temtronic", "newguy", "PCM programmer" and others that I don't remember at the moment..
 

mckenney

Joined Nov 10, 2018
125
and also a (thin) guide on how to use the LOCATION on TI's MSP wiki.
More recent MSP430 devices have the control registers grouped into blocks (the way e.g. ARMs do it) with consistent layouts, and define the BASE addresses and offsets. So you could in theory refer to P1_BASE->OUT or P2_BASE->IN (I think it isn't all quite there, but could be filled in). That gets you out of the "#pragma LOCATION" business, since it's all plain C.

They never did this for the F2/G2 series -- I suppose that's why there's no Driverllib for those -- since in those the layout is kind of a historical hodgepodge.
 

Thread Starter

StrongPenguin

Joined Jun 9, 2018
307
@ArakelTheDragon I've bought "The C Programming Language, 2nd Edition", but haven't quite finished my first book on C, which was for absolute beginners. I will look into that forum.

@mckenney Thanks for the tip. However, since I see PRAGMA showing up in many programs, I probably can't avoid it. And I like to learn new stuff.
 

ArakelTheDragon

Joined Nov 18, 2016
1,366
@ArakelTheDragon I've bought "The C Programming Language, 2nd Edition", but haven't quite finished my first book on C, which was for absolute beginners. I will look into that forum.

@mckenney Thanks for the tip. However, since I see PRAGMA showing up in many programs, I probably can't avoid it. And I like to learn new stuff.
Keep in mind that the book is good, but there are some inaccuracies in it do to the time it was written.

There is no language better than "C", there are languages which are easier (python, java, c++), but people often call easier better.
 
Top