0

Can anyone please tell me how to use ATMEGA8's USART to establish a full duplex serial communication with a laptop using a USB-to-Serial Adapter.

I am working on a project in which I need to display accelerometer reading in a gui. But the problem is I want to start sending the accelerometer data to laptop only when i send a character 's' to my ATMEGA8, which will then initiate continuous transfer of Accelerometer reading to the laptop. Also during this process, I want to send another character 't' to ATMEGA8 to stop the accelerometer data transfer.

Please help...

Thanks.

  • Have you tried anything at all and do you have the accelerometer otherwise working? If so please share what you've done so far, otherwise the question lacks too many details. – PeterJ Jul 09 '13 at 09:56

1 Answers1

1

Your question doesn't really fit the guidelines, I don't think...

Here's some pseudo code, implementation is left to the student:

if got 's', do loop

loop{
send_accel_data();
check_for_char(t);
if 't', break
}

It's easier if you have the sending and receiving interrupt driven, if your project is more complicated.

Marko
  • 825
  • 4
  • 8
  • Sorry for not mentioning the details of my project. I am able to successfully send accelerometer data to my laptop which is initiated on sending character 's'. But once data sending starts i am unable to stop it, when i send character 't'.Below is the AVR Studio 5 Code i have used in my Atmega8. – RAMKRISHNA VERMA Jul 09 '13 at 10:11
  • 'void main() { UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x4D; //for baud rate of 9600 unsigned char data,data1; data='u'; ADCEnable(); ADCSetMode(MODE_SINGLE_CONVERSION); ADCSetPrescaler(PRESCALE_64); ADMUX=0x04; while(1) { data1=uart_read(); if(data1=='s') { while(1) { unsigned char test; data=ADCStartConversion(); uart_num(data); //uart_char('\n'); test=uart_read(); if(test=='t') { break; } } } } }' – RAMKRISHNA VERMA Jul 09 '13 at 10:14
  • `void main() { UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x4D; //for baud rate of 9600 unsigned char data,data1; data='u'; ADCEnable(); ADCSetMode(MODE_SINGLE_CONVERSION); ADCSetPrescaler(PRESCALE_64); ADMUX=0x04; while(1) { data1=uart_read(); if(data1=='s') { while(1) { unsigned char test; data=ADCStartConversion(); uart_num(data); //uart_char('\n'); test=uart_read(); if(test=='t') { break; } } } } }' – RAMKRISHNA VERMA Jul 09 '13 at 10:20
  • @RAMKRISHNAVERMA, rather than post the code as a comment you can edit your original question to include it. Just make sure each level contains four spaces at the front so it gets formatted as code, you can see the preview of what it will look like below as you edit it. – PeterJ Jul 09 '13 at 10:21