Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Need help with UART

$
0
0

Hello,

 

I am writing a program to use LoRa RN2483 with MSP430G2553 sending to LoRa the readings from some sensors. First I had a temperature sensor DS18B20 (digital reading), the internal temperature from MSP, the internal supply voltage from MSP and the code worked great, the readings we're good and were succesfully sent to LoRa using UART.

 

Now I am trying to add a humidity sensor on P1.4 and a photoresistor on P1.5 ( using a 10k resistor like this: Vcc --- photoresistor -- P1.5 --- 10k resistor --- GND). These sensors are analogue so that I need 2 ADC to read them. I made something like this:

void humInit(void)
{
	ADC10CTL1 = INCH_4 + ADC10DIV_3 ;         // Channel 4, ADC10CLK/3
	ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable
	ADC10AE0 |= BIT4;                         // ADC input enable P1.4
}

int humOut(void)
{
	float value;
	__delay_cycles(1000);				// Wait for ADC Ref to settle
	ADC10CTL0 |= ENC + ADC10SC;			// Sampling and conversion start
	while (ADC10CTL1 & BUSY);             //waiting for conversion to finish
	value = ADC10MEM;				// Assigns the value held in ADC10MEM t
	ADC10CTL0&=~ENC;                     //disable adc conv
    return (unsigned int)(100-(value/1023 * 100));
}

and in the Main() function I have something like this:

humInit();
  hum = humOut();

where hum is a global variable.

 

The transmission part is something like this:

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCI0TX_ISR (void)
#else
#error Compiler not supported!
#endif
{
	if (f == '1')
		{
			UCA0TXBUF = string1[i++];       // TX next character
			 if (i == sizeof string1 - 1)              // TX over?
			 {
				 P1OUT|= BIT6;
			    __delay_cycles(5000000);
				 P1OUT&=~BIT6;
			    f = '2'; i = 0;
			 }
		}
		if (f == '2')
		{
			UCA0TXBUF = string2[i++];
			if (i == sizeof string2 - 1)
			 {
				P1OUT|= BIT6;
				__delay_cycles(2000000);
				P1OUT&=~BIT6;
			    f = '3'; i = 0;
			 }
		}
}

where f is a flag to know which string to send.

 

The transmission stars in Main() like:

  i = 0;
  f = '1';
  IE2 |= UCA0TXIE;   // Enable USCI_A0 TX interrupt
  UCA0TXBUF = string1[i++];

The problem is that after I'm adding the ADC for the humidity and read it (the reading is correct) the transmission stops after the first character of the first string. I tried to put a breakpoint in the TX interrupt and it doesn't seem to reach it. 

 

It seems that the ADC is somehow affecting the TX interrupt.

 

Any ideas on this ?

 

Thank you.

Attached Files

  • Attached File  main.c   7.66KB   1 downloads

Viewing all articles
Browse latest Browse all 2077

Trending Articles