#include <signal.h>
#include <io.h>

void usart_setup(void);
void adc_setup(void);

void adc_active(void) {
 ADC12IE |= 0x0002;
 ADC12CTL0 |= ENC+ADC12SC;
}

void adc_inactive(void) {
 ADC12IE &= 0;
 ADC12CTL0 &= 0xFFFF-(ENC+ADC12SC);
}

void u0Write(int len,char *buf) {
 int i;
 for(i=0; i < len; i++) {
   while( (UTXIFG0 & IFG1) != UTXIFG0 ){ ; }
   U0TXBUF = buf[i];
 }
}

void u0WriteInt(int i) {
 char *ptr;
 while((UTXIFG0 & IFG1) != UTXIFG0 ){ ; }
 ptr = (char *)&i;
 U0TXBUF = ptr[0];
 while((UTXIFG0 & IFG1) != UTXIFG0 ){ ; }
 U0TXBUF = ptr[1];
}

void uWriteb0(unsigned char c) {
 while( (UTXIFG0 & IFG1) != UTXIFG0 ){ ; }
 U0TXBUF = c;
}

int Channel;

int main() {
 /* Stop the WDT */
 WDTCTL = WDTPW+WDTHOLD;

 /* Clock Setup   *
  * SMCLK is 4Mhz */
_BIC_SR(OSCOFF);
  BCSCTL1 = 0x04;
  BCSCTL2 = SELS+DCOR;
/* Port Setup */
 usart_setup();
 adc_setup();

 IE1 |= URXIE0;

 _EINT();

 P1SEL = 0x00;
 P1DIR = 0x07;
 P1OUT |= 0x02;
 P1OUT &= 0x02;
 P1OUT |= 0x04;

 while(1) {
   /* The Sleep loop */
 }

 return 0;
}

void adc_setup(void){

 P6SEL = 0x07;
 P6DIR = 0xF8;

 ADC12CTL0 = 0x3390;
 ADC12CTL1 = 0x0202;
 ADC12MCTL0 = 0x00;
 ADC12MCTL1 = 0x01;
 ADC12MCTL2 = 0x82;    /* Last in Chain */
}

void usart_setup(void) {
/* Uart Setup */
 U0CTL = 0x01;
 U0TCTL = 0x30;
 UBR00=0x68; UBR10=0x00; UMCTL0=0x04;
ME1 |= UTXE0+URXE0; U0CTL = 0x10;
 P3SEL |= 0x30;
 P3DIR |= 0x10;
}

interrupt (UART0RX_VECTOR) usart0_rx(void) {
 char a = U0RXBUF;
 if(a == 'X') {
   /* Send X from ADC */
   Channel = 1;
   adc_active();
 }
 else if (a == 'Y') {
   /* Send Y from ADC */
   Channel = 2;
   adc_active();
 }
 else if (a == 'Z') {
   /* Send Z from ADC */
   Channel = 3;
   adc_active();
 }
 else if (a == 'A') {
   /* Send All channels */
   Channel = 0;
   adc_active();
 }
 else if (a == 'T') {
   uWriteb0('T');
 }
 else {
   /* Unknown Command */
 }

}

interrupt (ADC_VECTOR) adc12isr(void) {

 int adcval;
 if(Channel == 0) { /* All */
   adcval = ADC12MEM0;
   u0WriteInt(adcval);
   adcval = ADC12MEM1;
   u0WriteInt(adcval);
   adcval = ADC12MEM2;
   u0WriteInt(adcval);
 }
 else if (Channel == 1) { /* X */
   adcval = ADC12MEM0;
   u0WriteInt(adcval);
 }
 else if (Channel == 2) { /* Y */
   adcval = ADC12MEM1;
   u0WriteInt(adcval);
 }
 else if (Channel == 3) { /* Z */
   adcval = ADC12MEM2;
   u0WriteInt(adcval);
 }
 else {
   /* Unknown Channel */
 }
 adc_inactive();
}


Arnd-Hendrik Mathias wrote:

Hi Del,
sounds somewhat funny, could you post the complete source file(s)?
Arnd-Hendrik

Delbert Martin IV wrote:

I think I know what happend but I don't know why.
I switches the order that the parameters were passed to the function without changing the function definition. now the backwards variable were actually in the order that i passed them (wrong). so i changed the function definition to take the integer then the char * and it worked!

why?

--Del



Delbert Martin IV wrote:

msp430-gcc (GCC) 3.3.4
Running under Linux.

I have a problem with the Parameter passing. I set up a function.

u0Write(char *buf, int len) {
...
}

I then set up some data to pass
char *addr = &ADC12MEM0;
int buflength = 2;

then I call the function
u0Write(addr,bufferlength);

I tell the debugger to break at u0Write;
the Debugger prints out the parameters passed:
Breakpoint 1, u0Write (buf=0x2 "\202 À", len=320)
well here is the problem 320 (decimal == 0x140) and 0x02 is the value of the len parameter, looks like these are getting swapped somehow? anyown know why?

--Del


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users





-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Mspgcc-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users




Reply via email to