Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Serial data Communication problem!

Serial data Communication problem!

2004-04-13 by ereihani

HI!
Is it the right way of transmitting data via serial port?
I mean I put my data in UDR then in INT routine put the next data 
and so on.
I use Visual Basic for reading data but I don't get any data there!
I am also suspicious to my visual Basic program too!
Please guide me in both cases.
Regards,
Ehsan reihani





The C Program
------------------------------------------------------------
#include <mega16.h>
#include <delay.h>
int i=0;
interrupt [USART_DRE] void USART_DATA_REGISTER_EMPTY(void)
{
UDR=i;
PORTA=0xff;
}         

void main(void)
{         
UBRRL=0x0C;
UCSRB|=0x18;
UCSRC=0x86;
PORTA=0x00;
for(i=0;i<=9;i++) UDR=i;
}
---------------------------------------------------------------
The Visual Basic Program
'In VB I have used a mscomm and a command in my form
 
Private Sub Command1_Click()
Dim dr As Variant
MSComm1.CommPort = 1
MSComm1.OutBufferSize = 17
MSComm1.InBufferSize = 10
MSComm1.PortOpen = True
MSComm1.Handshaking = comRTS
MSComm1.RTSEnable = True
MSComm1.InputMode = comInputModeText
MSComm1.InputLen = 0
dr = MSComm1.Input
Text1.Text = dr
MSComm1.PortOpen = False
End Sub

Re: Serial data Communication problem!

2004-04-13 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "ereihani" <ereihani@y...> wrote:
> Is it the right way of transmitting data via serial port?
> I mean I put my data in UDR then in INT routine put the next data 
> and so on.

Well, one problem is that you never enable the interrupt on UDRE (bit 
5 of UCSRB).  If you're going to use the UDRE interrupt, you need to 
turn the enable on and off as new data is ready to be sent and old 
data is sent.  You probably should also implement a queue for data 
waiting to be sent and another one for data received.

There is example code, both for polled and interrupt driven serial 
comm, in AppNote AVR306 available here:
http://www.atmel.com/dyn/products/app_notes.asp?family_id=607

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.