EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

ADC and UART problems.

Started by "szymanski.l" January 15, 2008
Hi.

im kinda new to programing in the MSP430 and im having a little problem.

Im trying to do an ADC at the MSP430F149 and then send the results trough the UART using the RS232 connection, but i cant manage to do the UART interruption to work. It enters the ADC conversion and never leaves it. Can somebody please help? The is the following (using IAR).

The baud rate is fine (115200bps), as it works without the second interruption.

#include
static char results[4];
char i;

void main(void)
{

WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer

// ADC Inicializao
P6SEL = 0x0F; // Enable A/D channel inputs
ADC12CTL0 = ADC12ON+MSC+SHT0_8+REFON; // Turn on ADC12, extend sampling time
// to avoid overflow of results
ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
ADC12MCTL0 = INCH_0+SREF_1; // channel = A0
ADC12MCTL1 = INCH_1+SREF_1; // channel = A1
ADC12MCTL2 = INCH_2+SREF_1; // channel = A2
ADC12MCTL3 = INCH_3+SREF_1+EOS; // channel = A3, end seq.
ADC12IE = 0x08; // Enable ADC12IFG.3
ADC12CTL0 |= ENC; // Enable conversions


// UART Inicializao
P3SEL |= 0x10; // P3.4,5 = USART0 TXD
_BIS_SR(OSCOFF);
BCSCTL2 |= DCOR;
ME1 |= UTXE0; // Enable USART0 TXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL1;
UBR00 = 0x0E;
UBR10 = 0x00;
UMCTL0 = 0x44;
IE1 |= UTXIE0;
UCTL0 &= ~SWRST; // Initialize USART state machine
_EINT();
ADC12CTL0 |= ADC12SC; // Start conversion
for (;;);

}

#pragma vector=ADC_VECTOR
__interrupt void ADC12ISR (void)
{

results[0] = ADC12MEM0 >> 4; // Move A0 results, IFG is cleared
results[1]= ADC12MEM1 >> 4; // Move A1 results, IFG is cleared
results[2] = ADC12MEM2 >> 4; // Move A2 results, IFG is cleared
results[3] = ADC12MEM3 >> 4; // Move A3 results, IFG is cleared
TXBUF0 = results[i++];
}
// UART0 TX ISR
#pragma vector=UART0TX_VECTOR
__interrupt void usart0_tx (void)
{
if (i < sizeof results)
TXBUF0 = results[i++];
if (i == 4){
i = 0;
ADC12CTL0 |= ENC + ADC12SC;
}
}
Thank you in advance.



Beginning Microcontrollers with the MSP430

Nevermind, i solved the problem by putting the interruption enable bit to the end of the uart setup.

Now im getting another problem. I need it to run in high rate, about 900kbps for an usb port. But when i set my baud rate to get this speed, the code seems to lose itself and never leaves the uart interruption and i dont have any ideia about what is the problem. It only happens when im over about 200kbps. Can somebody help me?

Tnx!

> Hi.
>
> im kinda new to programing in the MSP430 and im having a little problem.
>
> Im trying to do an ADC at the MSP430F149 and then send the results trough the UART using the RS232 connection, but i cant manage to do the UART interruption to work. It enters the ADC conversion and never leaves it. Can somebody please help? The is the following (using IAR).
>
> The baud rate is fine (115200bps), as it works without the second interruption.
>
> #include
>
>
> static char results[4];
> char i;
>
> void main(void)
> {
>
> WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
>
> // ADC Inicializao
> P6SEL = 0x0F; // Enable A/D channel inputs
> ADC12CTL0 = ADC12ON+MSC+SHT0_8+REFON; // Turn on ADC12, extend sampling time
> // to avoid overflow of results
> ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer, repeated sequence
> ADC12MCTL0 = INCH_0+SREF_1; // channel = A0
> ADC12MCTL1 = INCH_1+SREF_1; // channel = A1
> ADC12MCTL2 = INCH_2+SREF_1; // channel = A2
> ADC12MCTL3 = INCH_3+SREF_1+EOS; // channel = A3, end seq.
> ADC12IE = 0x08; // Enable ADC12IFG.3
> ADC12CTL0 |= ENC; // Enable conversions
>
>
> // UART Inicializao
> P3SEL |= 0x10; // P3.4,5 = USART0 TXD
> _BIS_SR(OSCOFF);
> BCSCTL2 |= DCOR;
> ME1 |= UTXE0; // Enable USART0 TXD
> UCTL0 |= CHAR; // 8-bit character
> UTCTL0 |= SSEL1;
> UBR00 = 0x0E;
> UBR10 = 0x00;
> UMCTL0 = 0x44;
> IE1 |= UTXIE0;
> UCTL0 &= ~SWRST; // Initialize USART state machine
> _EINT();
> ADC12CTL0 |= ADC12SC; // Start conversion
> for (;;);
>
> }
>
> #pragma vector=ADC_VECTOR
> __interrupt void ADC12ISR (void)
> {
>
> results[0] = ADC12MEM0 >> 4; // Move A0 results, IFG is cleared
> results[1]= ADC12MEM1 >> 4; // Move A1 results, IFG is cleared
> results[2] = ADC12MEM2 >> 4; // Move A2 results, IFG is cleared
> results[3] = ADC12MEM3 >> 4; // Move A3 results, IFG is cleared
> TXBUF0 = results[i++];
>
>
> }
> // UART0 TX ISR
> #pragma vector=UART0TX_VECTOR
> __interrupt void usart0_tx (void)
> {
> if (i < sizeof results)
> TXBUF0 = results[i++];
> if (i == 4){
> i = 0;
> ADC12CTL0 |= ENC + ADC12SC;
> }
> }
>
>
> Thank you in advance.
>
>



I think the reason may be that you are sending the bits so fast, that
while you exit usart0_tx(), the whole byte is sent and the TX buffer
is empty again, setting TX interrupt flag and triggering another
usart0_tx(), before the processor has time to realize there is an ADC
interrupt pending.
In another words, USART takes less time to send the byte than it takes
to process usart0_tx().

Anyway, I think you are missinterpreting the way how TX interrupt
works. TX is not only generated when TXBUF changes from busy to empty,
but as long as TXBUF is empty, which means that if "i < sizeof
results" is false, TXBUF will never be filled and thus an TX interrupt
will always be pending, and your processor will be stuck calling
usart0_tx()

Best Regards,
Michael Kusch

--- In m..., "szymanski\.l" wrote:
>
> Nevermind, i solved the problem by putting the interruption enable
bit to the end of the uart setup.
>
> Now im getting another problem. I need it to run in high rate,
about 900kbps for an usb port. But when i set my baud rate to get this
speed, the code seems to lose itself and never leaves the uart
interruption and i dont have any ideia about what is the problem. It
only happens when im over about 200kbps. Can somebody help me?
>
> Tnx!
>
>
>
> > Hi.
> >
> > im kinda new to programing in the MSP430 and im having a little
problem.
> >
> > Im trying to do an ADC at the MSP430F149 and then send the
results trough the UART using the RS232 connection, but i cant manage
to do the UART interruption to work. It enters the ADC conversion and
never leaves it. Can somebody please help? The is the following (using
IAR).
> >
> > The baud rate is fine (115200bps), as it works without the second
interruption.
> >
> > #include
> >
> >
> > static char results[4];
> > char i;
> >
> > void main(void)
> > {
> >
> > WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
> >
> > // ADC Inicializao
> > P6SEL = 0x0F; // Enable A/D channel
inputs
> > ADC12CTL0 = ADC12ON+MSC+SHT0_8+REFON; // Turn on ADC12,
extend sampling time
> > // to avoid overflow
of results
> > ADC12CTL1 = SHP+CONSEQ_3; // Use sampling timer,
repeated sequence
> > ADC12MCTL0 = INCH_0+SREF_1; // channel = A0
> > ADC12MCTL1 = INCH_1+SREF_1; // channel = A1
> > ADC12MCTL2 = INCH_2+SREF_1; // channel = A2
> > ADC12MCTL3 = INCH_3+SREF_1+EOS; // channel = A3, end seq.
> > ADC12IE = 0x08; // Enable ADC12IFG.3
> > ADC12CTL0 |= ENC; // Enable conversions
> >
> >
> > // UART Inicializao
> > P3SEL |= 0x10; // P3.4,5 = USART0 TXD
> > _BIS_SR(OSCOFF);
> > BCSCTL2 |= DCOR;
> > ME1 |= UTXE0; // Enable USART0 TXD
> > UCTL0 |= CHAR; // 8-bit character
> > UTCTL0 |= SSEL1;
> > UBR00 = 0x0E;
> > UBR10 = 0x00;
> > UMCTL0 = 0x44;
> > IE1 |= UTXIE0;
> > UCTL0 &= ~SWRST; // Initialize USART
state machine
> > _EINT();
> > ADC12CTL0 |= ADC12SC; // Start conversion
> > for (;;);
> >
> > }
> >
> > #pragma vector=ADC_VECTOR
> > __interrupt void ADC12ISR (void)
> > {
> >
> > results[0] = ADC12MEM0 >> 4; // Move A0 results, IFG is cleared
> > results[1]= ADC12MEM1 >> 4; // Move A1 results, IFG is cleared
> > results[2] = ADC12MEM2 >> 4; // Move A2 results, IFG is
cleared
> > results[3] = ADC12MEM3 >> 4; // Move A3 results, IFG is
cleared
> > TXBUF0 = results[i++];
> >
> >
> > }
> > // UART0 TX ISR
> > #pragma vector=UART0TX_VECTOR
> > __interrupt void usart0_tx (void)
> > {
> > if (i < sizeof results)
> > TXBUF0 = results[i++];
> > if (i == 4){
> > i = 0;
> > ADC12CTL0 |= ENC + ADC12SC;
> > }
> > }
> >
> >
> > Thank you in advance.
> >
>




The 2024 Embedded Online Conference