Hi Freaks,
I am using an Atmega48 ADC to collect some samples of a sine wave. I am trying to save samples in the M48 RAM (512 bytes). I am using an array of 256 bytes to store each 8 bit value and when all 256 bytes have been saved, I am transmitting the RAM contents through UART.
Here is my code:
#include#include #include #include #define USART_BAUDRATE 115200 #define BAUD_PRESCALE (((14746000/ (USART_BAUDRATE * 16UL))) - 1) //value to load into UBRR volatile unsigned char ADC_Buffer[256]; volatile unsigned char i,j; volatile unsigned char flag; void USART0_init() { UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Turn on the transmission and reception circuitry UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); //Set to 8 bit no parity, 1 stop bit UBRR0L = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register UBRR0H = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register } void USART_putchar(unsigned char c) { while ((UCSR0A & (1 << UDRE0)) == 0) {}; UDR0 = c; } void ADC_init() { ADCSRA |= (1 << ADPS2) | (1 << ADPS0) | (1 << ADATE); //using /32 prescalar ADMUX = (1 << REFS0) | (1 << MUX2) | (1 << MUX0) | (1 << ADLAR); // Set ADC reference to AVCC,select channel 5 //using all 10 bit of ADC; so do not left justify the ADC value DIDR0 = (1 << ADC5D); //turn off the digital driver ADCSRA |= (1 << ADEN); // Enable ADC ADCSRA |= (1 << ADIE); // Enable ADC Interrupt sei(); // Enable Global Interrupts ADCSRA |= (1 << ADSC); // Start A2D Conversions } void timer_init() { TCCR1B |= (1 << WGM12); TIMSK1 |= (1 << OCIE1A); sei(); OCR1A = 2000; TCCR1B |= (1 << CS12) | (0 << CS11) | (0 << CS10); } ISR(TIMER1_COMPA_vect) { PORTD ^= (1 <<PORTD7); } ISR(ADC_vect) { if(i<256) { ADC_Buffer[i] = ADCH; i++; } else { flag = 1; } } int main (void) { DDRC = 0x0F; DDRD = 0xC0; USART0_init(); ADC_init(); timer_init(); for(;;) { ADCSRA |= (1 << ADSC); if(flag==1) { for(j=0;j<256;j++) { USART_putchar(ADC_Buffer[j]); } } } }
I am not getting anything in my capture file from the hyperterminal. What may be missing?
Thanks.