0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 9, 2013 at 9:56

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jul 9, 2013 at 10:11
  • \$\begingroup\$ '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; } } } } }' \$\endgroup\$ Commented Jul 9, 2013 at 10:14
  • \$\begingroup\$ <code>`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; } } } } }'</code> \$\endgroup\$ Commented Jul 9, 2013 at 10:20
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Jul 9, 2013 at 10:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.