Atmeg168 10 bit ADC code.

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

Hi,
I can't understand the ADC code for the Sparkfun IMU Module. I have to write code for the receiver to recive data from the IMU. but don't know how the transmitter sends the data. here is the part of code.....any ideas how it works...thanks

if (active_channels & (1<<x_active))
		{	
ADMUX = 0x40;
ADCSRA = (1 << ADEN)|(1 << ADSC)|(1<<ADPS2)(1<<ADPS1);
			
			while(ADCSRA & (1 << ADSC));
			l2 = (ADCL & 0xFF);
			h2 = (ADCH & 0x03);
			x_accel = ((h2<<8) | l2);
			
			if (asc == 0)
            {
                a = (((short)x_accel & 0xFF00) >> 8);
                q = (char)a;
                put_char(q);
                q = (char)x_accel & 0xFF;
                put_char(q);
            }//put_char and get_char are functions to  send data to serial data to USART
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Before writing the code learn to read and understand the code. Get a good C book and read it.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

It sends data trough USART, and I think you can find a tutorial about USART communication on the tutorial section, good luck with it!

tutorial link:
https://www.avrfreaks.net/index.p...