EmbeddedRelated.com
Forums

Storing and reading a value from RAM

Started by wurship March 19, 2009
Can someone please help me?

I am new to microcontrollers and hobbeling along with C. I am using code composer and the TI example programs.

I can get the MSP430(MSP430F2252) to echo back a uart value when it is received, and I can get the MSP430 to read a value from an input on the ADC10. I can see the correct value in the debug interface.

What I need to do is take the value in ADC10MEM and store away. Then I need to keep doing this until in interupt is launched at the UART. I understand there are four memory sections labled A, B, C, and D. This would be ideal for me because I am going to be taking readings from four different voltage sources.

Can someone show me what C code would store a value from ADC10MEM into RAM and then back to UCA0TXBUF?

Thanks

Beginning Microcontrollers with the MSP430

"wurship" :

> Can someone please help me?
>
> I am new to microcontrollers and hobbeling along with C. I am using
> code composer and the TI example programs.
>
> I can get the MSP430(MSP430F2252) to echo back a uart value when it is
> received, and I can get the MSP430 to read a value from an input on the
> ADC10. I can see the correct value in the debug interface.
>
> What I need to do is take the value in ADC10MEM and store away. Then I
> need to keep doing this until in interupt is launched at the UART. I
> understand there are four memory sections labled A, B, C, and D. This
> would be ideal for me because I am going to be taking readings from four
> different voltage sources.
>
> Can someone show me what C code would store a value from ADC10MEM into
> RAM and then back to UCA0TXBUF?

Use a global variable:

int buf;

void adcinterrupt( void )
{
....
bufC10MEM;
....
}

void uartinterrupt( void )
{
....
UCA0TXBUF=buf;
....
}

M.

Info A B C D are part of flash and are used for storing calibration
data and the likes.

Mate I suggest you pick up a book about micros or even c and have a
read first. This is an absolute basic fundamental of any embedded
design.

Do this before asking for some to do your homework for you...

I'll give u a hint: int x;

Hani

Sent from my iPhone

On 20/03/2009, at 12:58 AM, "wurship" wrote:

> Can someone please help me?
>
> I am new to microcontrollers and hobbeling along with C. I am using
> code composer and the TI example programs.
>
> I can get the MSP430(MSP430F2252) to echo back a uart value when it
> is received, and I can get the MSP430 to read a value from an input
> on the ADC10. I can see the correct value in the debug interface.
>
> What I need to do is take the value in ADC10MEM and store away. Then
> I need to keep doing this until in interupt is launched at the UART.
> I understand there are four memory sections labled A, B, C, and D.
> This would be ideal for me because I am going to be taking readings
> from four different voltage sources.
>
> Can someone show me what C code would store a value from ADC10MEM
> into RAM and then back to UCA0TXBUF?
>
> Thanks


Hi,

To simplify the example, let's just assume that your ADC data is in a
location called ADC10MEM, and that you're storing back to a location
UCA0TXBUF. The rest you can fill out :-)

I'm not sure if I would rely on this A/B/C/D sections (partially because
I'm not familiar with F2252), because most C compilers (AFAIK)
(try to) treat memory as one contiguous section.
When the F1611 was released, there TI certainly arranged the address
decoding so the original 2K RAM was still where it was before,
but also mirrored up higher so it seamlessly turns the extra 8K into one
10K RAM section.
This makes the compiler's job a heck of a lot easier.

Ok, so there are several ways to code what you want.
One of the easiest/clear ways would be to use multi dimension arrays I
think.

I assume your ADC is set up to store into successive ADC10MEMx locations
and that the ADC10 interrupt then needs to fetch those locations and write
them to RAM. I'm not covering that (as above) - I'm just using the ADC10MEM
"as is".

Say you want to store 4 channels each with - say - 64 samples.

Declare a global array :

unsigned short my_samples [4][64];

1. storing a sample (eg. sample # 23 on Channel 2) :

my_samples[2][23] = ADC10MEM;

2. Reading that sample back to write to UCA0TXBUF :

UCA0TXBUF = my_samples[2][23];

All you need to do now is to assign variables to the Channel # and Sample
#, for example :

unsigned char channel_num, sample_num;

and your code would then read from or write to the array :

my_samples[channel_num][sample_num]

I don't think you need anything more than that to get started with
something basic.
Just make sure that - if you indeed use multiple ADCMEM locations - there
is proper synchronisation between the ADC interrupt
and the 'foreground' code (commonly referred to as "bottom half"), so you
only read back results after they have been updated by the ADC10 code
properly.
HTH
Best regards,
Kris
On Thu, 19 Mar 2009 13:58:42 -0000, "wurship"
wrote:
> Can someone please help me?
>
> I am new to microcontrollers and hobbeling along with C. I am using code
> composer and the TI example programs.
>
> I can get the MSP430(MSP430F2252) to echo back a uart value when it is
> received, and I can get the MSP430 to read a value from an input on the
> ADC10. I can see the correct value in the debug interface.
>
> What I need to do is take the value in ADC10MEM and store away. Then I
> need to keep doing this until in interupt is launched at the UART. I
> understand there are four memory sections labled A, B, C, and D. This
> would be ideal for me because I am going to be taking readings from four
> different voltage sources.
>
> Can someone show me what C code would store a value from ADC10MEM into
RAM
> and then back to UCA0TXBUF?
>
> Thanks
>
>