EmbeddedRelated.com
Forums

DTC Issue regarding reading of RAM memory??

Started by roknudson March 3, 2008
Hi All,

I'm having some difficulty reading from RAM consistently using the
__data16 pointer structure. I could swear that it was all working one
day and then the next it's like my pointer assignment doesn't work.
I'm using the DTC to read five ADC10 channels. That part works. I
can look at the memory in my debug window and it reflects appropriate
analog levels.

I really just need a simple way to use that RAM data in my program
code. Is the __data16 assignment done correctly?
Thanks, for any help. This has been a show stopper for longer than I
care to admit.

Thanks,
Rob

Here's my code:
//*************************************************************
// Main routine, this is where all the action takes place. The ADC
is read
// and adjustments are made to the PWM based on the results. Shutdown
// procedures are also handled here.
//*************************************************************
void main(void)
{
int __data16 * LED_VOLT;
int __data16 * LED_AMP;
int __data16 * LED_THERM;
int __data16 * LED_INT;
int __data16 * LED_BUS;
int test2;

*LED_BUS = 0x200;
*LED_INT = 0x202;
*LED_THERM = 0x204;
*LED_AMP = 0x206;
*LED_VOLT = 0x208;

//
// Initialize ADC/Variables/Ports/Constants
//
init();

//
//enter main loop
//
while(1)
{

ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is
ADC10SA = 0x200; // Data buffer start
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion
_BIS_SR(CPUOFF + GIE); // LPM0, ADC10_ISR will

//Calculate Intensity
//Check safety limits
//Check I and V limits
//Check T limits
//pwm(newIntensity);

//
//Check Saftey
//
__disable_interrupt();

if (LED_AMP[0] < 0x00 | LED_VOLT[0] > 0xFFF | LED_THERM[0] > 0xFFF)
test2++; //do some action (implement later)
__enable_interrupt();

}

}//end main routine

// ADC10 interrupt service routine
#pragma vectorC10_VECTOR
__interrupt void ADC10_ISR (void)
{
_BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from
}

Beginning Microcontrollers with the MSP430

Hi!

First, unless you are using MSP430X and the large data model (which I
don't think you are) then you don't have to specify the __data16 memory
attribute.

Secondly, your code is plain wrong. If you want to access a peripheral
unit you should declare it using the special "@" syntax, and access it
as a plain variable, for example:

int LED_VOLT @ 0x200;

void main()
{
LED_VOLT = 10;
}

-- Anders Lindgren, IAR Systems

Ps. If you really want to use your pointer approach, you should
initialize the pointers with the following:

LED_VOLT = (int *)0x208;

In your code, you're assigning 0x208 to whatever LED_VOLT points to
(which could be anything since it's not initialized).

roknudson wrote:
> Hi All,
>
> I'm having some difficulty reading from RAM consistently using the
> __data16 pointer structure. I could swear that it was all working one
> day and then the next it's like my pointer assignment doesn't work.
> I'm using the DTC to read five ADC10 channels. That part works. I
> can look at the memory in my debug window and it reflects appropriate
> analog levels.
>
> I really just need a simple way to use that RAM data in my program
> code. Is the __data16 assignment done correctly?
> Thanks, for any help. This has been a show stopper for longer than I
> care to admit.
>
> Thanks,
> Rob
>
> Here's my code:
> //*************************************************************
> // Main routine, this is where all the action takes place. The ADC
> is read
> // and adjustments are made to the PWM based on the results. Shutdown
> // procedures are also handled here.
> //*************************************************************
> void main(void)
> {
> int __data16 * LED_VOLT;
> int __data16 * LED_AMP;
> int __data16 * LED_THERM;
> int __data16 * LED_INT;
> int __data16 * LED_BUS;
> int test2;
>
> *LED_BUS = 0x200;
> *LED_INT = 0x202;
> *LED_THERM = 0x204;
> *LED_AMP = 0x206;
> *LED_VOLT = 0x208;
>
> //
> // Initialize ADC/Variables/Ports/Constants
> //
> init();
>
> //
> //enter main loop
> //
> while(1)
> {
>
> ADC10CTL0 &= ~ENC;
> while (ADC10CTL1 & BUSY); // Wait if ADC10 core is
> ADC10SA = 0x200; // Data buffer start
> ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion
> _BIS_SR(CPUOFF + GIE); // LPM0, ADC10_ISR will
>
> //Calculate Intensity
> //Check safety limits
> //Check I and V limits
> //Check T limits
> //pwm(newIntensity);
>
> //
> //Check Saftey
> //
> __disable_interrupt();
>
> if (LED_AMP[0] < 0x00 | LED_VOLT[0] > 0xFFF | LED_THERM[0] > 0xFFF)
> test2++; //do some action (implement later)
> __enable_interrupt();
>
> }
>
> }//end main routine
>
> // ADC10 interrupt service routine
> #pragma vectorC10_VECTOR
> __interrupt void ADC10_ISR (void)
> {
> _BIC_SR_IRQ(CPUOFF); // Clear CPUOFF bit from
> }
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Hi,

> I'm having some difficulty reading from RAM consistently using the
> __data16 pointer structure. I could swear that it was all working one
> day and then the next it's like my pointer assignment doesn't work.
> I'm using the DTC to read five ADC10 channels. That part works. I
> can look at the memory in my debug window and it reflects appropriate
> analog levels.
>
> I really just need a simple way to use that RAM data in my program
> code. Is the __data16 assignment done correctly?
> Thanks, for any help. This has been a show stopper for longer than I
> care to admit.
>
> Thanks,
> Rob
>
> Here's my code:
> //*************************************************************
> // Main routine, this is where all the action takes place. The ADC
> is read
> // and adjustments are made to the PWM based on the results.
> Shutdown
> // procedures are also handled here.
> //*************************************************************
> void main(void)
> {
> int __data16 * LED_VOLT;
> int __data16 * LED_AMP;
> int __data16 * LED_THERM;
> int __data16 * LED_INT;
> int __data16 * LED_BUS;
> int test2;
>
> *LED_BUS = 0x200;
> *LED_INT = 0x202;
> *LED_THERM = 0x204;
> *LED_AMP = 0x206;
> *LED_VOLT = 0x208;

Oh my. Oh my, oh my. Read a book on C before you try programming in it.
Doesn't the IAR compiler tell you you're being an idiot here, using an
uninitialized variable?

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
Idiot, here.

Thanks.
--- In m..., Anders Lindgren
wrote:
>
> Paul Curtis wrote:
> > > void main(void)
> > > {
> > > int __data16 * LED_VOLT;
> > > int __data16 * LED_AMP;
> > > int __data16 * LED_THERM;
> > > int __data16 * LED_INT;
> > > int __data16 * LED_BUS;
> > > int test2;
> > >
> > > *LED_BUS = 0x200;
> > > *LED_INT = 0x202;
> > > *LED_THERM = 0x204;
> > > *LED_AMP = 0x206;
> > > *LED_VOLT = 0x208;
> >
> > Oh my. Oh my, oh my. Read a book on C before you try programming
in it.
> > Doesn't the IAR compiler tell you you're being an idiot here, using an
> > uninitialized variable?
>
> Unfortunately, our marketing department thinks it's bad business to
call
> customers "idiots", but we do generate the following:
>
> *LED_BUS = 0x200;
> ^
> "E:\src\test\msp430\uninit.c",4 Warning[Pe549]: variable "LED_BUS" is
> used before its value is set
>
> -- Anders Lindgren, IAR Systems
> --
> Disclaimer: Opinions expressed in this posting are strictly my own and
> not necessarily those of my employer.
>
Heh,

It's ironic that the OP's symptoms are the classic one : All goes well (while the stray pointer is
having a ball), the program grows and then suddenly all hell breaks lose !
Naturally the programmer thinks it's the last step made that caused the problem so here we go.

I had this when I first started on C. I was doing something stupid like buffering a string in a
temp pointer (that was not initialised)... Worked just dandy till I wrote another 60 kB of code or
so - Yowza !! Took me 2 F-ing days to find the problem !
Well, I never forgot that.

Oh well, we've all been newbies once I guess (at least I've been :-), but (some) newbies sometimes
- eventually - can become a source of information as well :-)

PS : To write the target RAM address to the pointed variable, instead of the pointer itself is of
course plain silly... That is - I presume that the idea was that the ADC values are stored in
0x200 onwards....

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of Anders Lindgren
Sent: Tuesday, 4 March 2008 3:51 AM
To: m...
Subject: Re: [msp430] DTC Issue regarding reading of RAM memory??

Paul Curtis wrote:
> > void main(void)
> > {
> > int __data16 * LED_VOLT;
> > int __data16 * LED_AMP;
> > int __data16 * LED_THERM;
> > int __data16 * LED_INT;
> > int __data16 * LED_BUS;
> > int test2;
> >
> > *LED_BUS = 0x200;
> > *LED_INT = 0x202;
> > *LED_THERM = 0x204;
> > *LED_AMP = 0x206;
> > *LED_VOLT = 0x208;
>
> Oh my. Oh my, oh my. Read a book on C before you try programming in it.
> Doesn't the IAR compiler tell you you're being an idiot here, using an
> uninitialized variable?

Unfortunately, our marketing department thinks it's bad business to call
customers "idiots", but we do generate the following:

*LED_BUS = 0x200;
^
"E:\src\test\msp430\uninit.c",4 Warning[Pe549]: variable "LED_BUS" is
used before its value is set

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Paul Curtis wrote:
> > void main(void)
> > {
> > int __data16 * LED_VOLT;
> > int __data16 * LED_AMP;
> > int __data16 * LED_THERM;
> > int __data16 * LED_INT;
> > int __data16 * LED_BUS;
> > int test2;
> >
> > *LED_BUS = 0x200;
> > *LED_INT = 0x202;
> > *LED_THERM = 0x204;
> > *LED_AMP = 0x206;
> > *LED_VOLT = 0x208;
>
> Oh my. Oh my, oh my. Read a book on C before you try programming in it.
> Doesn't the IAR compiler tell you you're being an idiot here, using an
> uninitialized variable?

Unfortunately, our marketing department thinks it's bad business to call
customers "idiots", but we do generate the following:

*LED_BUS = 0x200;
^
"E:\src\test\msp430\uninit.c",4 Warning[Pe549]: variable "LED_BUS" is
used before its value is set

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.