Serial Communications Issue

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay I am trying to get my project to comunicate to my computer....the problem being at it is supposed to only update the Uart once so I only get the info once on my computer, but instead it is continously up dating the following.

TeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTe
TeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTe
TeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTeTe

So on and so Fourth.

I have commented out the LCD and Button press routines to try and find out the Problem and it has been narrowed down to the ADC.I am using Dragon Rider 500, Atmega32 running at 8Mhz on Internal Oscillator.

int main(void)
{
	DDRA = 0x00;
	DDRB = 0x00;
	PORTB = 0xFF; 
	ADCSRA |= (1<<ADEN); //Turn on ADC
	ADCSRA |= (1<<ADIE); //Enable ADC Interupt
	ADCSRA |= ((1<<ADPS2) | (1<<ADPS0)); // Prescaller of 32 
	lcd_init(LCD_DISP_ON); //turn on lcd and turn curser off
	uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );// select Baud rate
	sei(); // enable Global Interupts
	

	while(1)
	{
		//LCD_Update();
		Uart_Update();
		ADC_Update();
		//Button_Press();
		
		
		
	}
}

here is the Uart Update code

void Uart_Update()
{
	if (Update ==1)
	{
		uart_puts("Test\r");
		uart_puts("String stored in SRAM\r");
		Update = 0;
	}

}

Update is a Global variable initially set to 1

And here is the ADC code

void ADC_Update()
{
	ADMUX = 0x00; //choose adc input #1 and select external reference!
	ADCSRA |= (1<<ADSC); //Start ADC Conversion
	_delay_ms(25);
	Temp = ADCL;
	PH = ((Temp * 2.5)/256);
	ADMUX = 0x01; //choose adc input #2 and select external reference!
	ADCSRA |= (1<<ADSC); //Start ADC Conversion
	_delay_ms(25);
	Temp = ADCL;
	ORP = ((Temp * 2.5)/256);
	//Update = 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check the sticky at the top of the main Forum about giving all necessary info.

We have part of the picture, but not all of it. In particular are USART comms interrupt driven? What happens when the transmit buffer fills up?

[If you send a 'U' character in a loop every fraction of a second, does it keep going?]

What speed your AVR? What speed your USART? Would 2 or 3 byte times be about the watchdog interval? Is WDTON set?

Quote:

Temp = ADCL;

This may not give you the result you think. See the datasheet about reading of ADCH and ADCL.

Quote:

PH = ((Temp * 2.5)/256);

Is PH a flat? (Why burden a simple program with floating point, but I guess that is up to you.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry missed some info

Baud Rate = 9600
Using Peter Fleury's Uart Lib
F_CPU = 8Mhz

temp = ADCL; should give me the lower 8 bits which is all I am looking for!

PH and ORP variables get conditioned in my LCD Routine for now!! so their values are not important at the moment

If I comment out the ADC Routine everything works fine the Uart updates my computer once...But as soon as I uncomment the ADC is when is gets messed up again!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fixed my own problem ...the problem was that I had the adc interupt enabled but wasn't using it in my ADC routin so the ADC interupt was going off partially through my Uart Update causeing it to cycle

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

temp = ADCL; should give me the lower 8 bits which is all I am looking for!

Will it? (If you want 8 bits use ADLAR and ADCH).
Quote:

This may not give you the result you think. See the datasheet about reading of ADCH and ADCL.


Quote:
The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL. By default, the result is presented right adjusted, but can optionally be presented left adjusted by setting the ADLAR bit in ADMUX.

If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is read, neither register is updated and the result from the conversion is lost. When ADCH is read, ADC access to the ADCH and ADCL Registers is
re-enabled.

Trust me--I wouldn't lie to you about something this serious.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks...I don't know how I miss read that in the spec sheet!!!