ece
Mar 12 2008, 9:57 PM
we are working on project controlling of stepper motor through AVR microcontroller using serial communication.in that as a part of testing we are to transmit any one bit data and receive same bit.we are using AVR STUDIO4 software.pls guide us with instruction of serial communication as soon as possible
abbas1707
Mar 13 2008, 2:12 AM
check AVR serial tutorial
ece
Mar 13 2008, 4:15 AM
we have already gone through it and we made program by reffering that but it is not working for transmitting and receiving a bipls,send proper program for that.
Ajay
Mar 13 2008, 10:17 AM
which AVR you are using?
ece
Mar 16 2008, 10:42 PM
AT MEGA32.
ece
Mar 17 2008, 3:07 AM
actualy we have to send and recieve a bit through port D of AT MEGA32 i.e on port D.0 and port D.1 we are not getting wat to do for program how to write.pls guide
abbas1707
Mar 17 2008, 11:13 AM
why D.0 and D.1 ?? you can do it on any pin... just send them/ receive serially
Ajay
Mar 17 2008, 12:18 PM
abbas, PD.0 is RXD and PD.1 is TXD..
can i see your code ece..?
can i see your code ece..?
ece
Mar 17 2008, 10:21 PM
Here is our program.pls check it and make the necessary changes.
CODE:
.include"m32def.inc"
.def reg1= r16
.def reg2=r17
.def reg3=r18
.def reg4=r19
Serial_Init:
ldi reg1,00
out UBRRH,reg1
LDI reg1,25
OUT UBRRL,reg1
ldi reg4,( 1<<RXEN)|(1<<TXEN)
out UCSRB,reg4
//ldi reg1,00
ldi reg1,(1<<URSEL)+(1<<USBS)+(3<<UCSZ0)
OUT UCSRC,reg1
//sbi UCSRA,RXC
USART_Transmit:
sbis UCSRA,UDRE
rjmp USART_Transmit
ldi reg1,0XFF
out UDR,reg1
sbi UCSRA,TXC
USART_Receive:
sbis UCSRA,RXC
rjmp USART_Receive
in reg3,UDR
out PORTA,reg3
ret
.def reg1= r16
.def reg2=r17
.def reg3=r18
.def reg4=r19
Serial_Init:
ldi reg1,00
out UBRRH,reg1
LDI reg1,25
OUT UBRRL,reg1
ldi reg4,( 1<<RXEN)|(1<<TXEN)
out UCSRB,reg4
//ldi reg1,00
ldi reg1,(1<<URSEL)+(1<<USBS)+(3<<UCSZ0)
OUT UCSRC,reg1
//sbi UCSRA,RXC
USART_Transmit:
sbis UCSRA,UDRE
rjmp USART_Transmit
ldi reg1,0XFF
out UDR,reg1
sbi UCSRA,TXC
USART_Receive:
sbis UCSRA,RXC
rjmp USART_Receive
in reg3,UDR
out PORTA,reg3
ret
sashijoseph
Mar 18 2008, 9:06 AM
What clock are you using?
ece
Mar 18 2008, 10:05 PM
we dont know whether to use clock or not.we are new to this concept.can u help in modifying our program or send us new one that can run.
Ajay
Mar 19 2008, 12:41 AM
Please go through the tutorial and datasheet. Write something and if you get any problem then post here.
We do not provide codes as such you know that. So you can take the tutorial codes as reference.
One suggestion.. use normal timers to provide delay, after half time of make the transition on port pin..
lets say your 100mS is the total time.. so 50mS for high and 50mS for low, will give you 100mS of square wave with equal proportion.
Just convert the frequency to time period (total time) and then generate delay of half the time.
We do not provide codes as such you know that. So you can take the tutorial codes as reference.
One suggestion.. use normal timers to provide delay, after half time of make the transition on port pin..
lets say your 100mS is the total time.. so 50mS for high and 50mS for low, will give you 100mS of square wave with equal proportion.
Just convert the frequency to time period (total time) and then generate delay of half the time.
ece
Mar 24 2008, 10:41 PM
we are not getting u.can u pls make necessary changes in the code that we sent u.
sashijoseph
Mar 25 2008, 1:04 AM
Your code seems to be ok.
Are you using an external 4Mhz crystal?
Can you tell us about your hardware connections....like crystal,reset pin,uart pins etc.
Have you programmed the fuse bits? If not then you shouldn't be using an externl crystal coz the Atmega(when bought new and with no fuse bits done) defaults to a 1Mhz internal rc clock.
Which programmer are you using?
Finally I would suggest writing a small LED blinking program for portA or portB and checking whether your chip is working in the 1st place.
Are you using an external 4Mhz crystal?
Can you tell us about your hardware connections....like crystal,reset pin,uart pins etc.
Have you programmed the fuse bits? If not then you shouldn't be using an externl crystal coz the Atmega(when bought new and with no fuse bits done) defaults to a 1Mhz internal rc clock.
Which programmer are you using?
Finally I would suggest writing a small LED blinking program for portA or portB and checking whether your chip is working in the 1st place.
ece
Mar 25 2008, 1:41 AM
v hav already tested the chip wid simple led programs. v r using a 16Mhz external
crystal. v can transmit through our program btwen it comes in recieve mode UDR bit goes zero. v saw this in IO view of AVR STUDIO4 nd have nt done practically wid kit
crystal. v can transmit through our program btwen it comes in recieve mode UDR bit goes zero. v saw this in IO view of AVR STUDIO4 nd have nt done practically wid kit
Ajay
Mar 25 2008, 10:08 AM
may i take a look at your program once?
sashijoseph
Mar 25 2008, 12:11 PM
It's in the 1st page,Ajay.
Ajay
Mar 25 2008, 1:14 PM
is that program correct? Its just subroutines.. where is the main routine?
and UDR is a register not a bit.
and UDR is a register not a bit.
sashijoseph
Mar 25 2008, 11:53 PM
ece wrote ...
v hav already tested the chip wid simple led programs. v r using a 16Mhz external
crystal. v can transmit through our program btwen it comes in recieve mode UDR bit goes zero. v saw this in IO view of AVR STUDIO4 nd have nt done practically wid kit
UDR bit??You meant UDRregister(byte) didn't you.
In I/O view of AVR Studio you will get UDR=0x00 because there's no hardware UART simulation provided by which you can latch in a byte to the RX shift register and from there to the UDR.
Probably you are assuming that the TX byte you sent out should be received into UDR by your 'receive' routine.But this is possible only in hardware when you loop back the byte by shorting the TX and RX pins.
Not possible in simulation.
So burn your program and test in hardware.
pdi33
Apr 13 2008, 2:37 AM
just check if the IC is ATmega32 or ATmeag32L. If it is ATmeag32L, then the max. frequency it can operate is 8mhz and not 16mhz.
download WinAVR GCC( it is free!!) . It automatically integrates with AVRstudio4. U will find writing a c program much easier especially for serial communication as the WinAVR has a great library for serial communication for AVRs.
download WinAVR GCC( it is free!!) . It automatically integrates with AVRstudio4. U will find writing a c program much easier especially for serial communication as the WinAVR has a great library for serial communication for AVRs.
MATHIVANAN
Jul 7 2008, 5:12 AM
i am also having same problem in AVR -ATMEGA32Lworking at 8Mhz(baud reate=0x33). i am using MAX232CPE chip for RS232 to TTL converter. i am having USB to Serial converter for USb to RS232 Interface. When i am loop back the TTL output of the MAX232CPE, the data i am sending and getting on my PC is Correct, but when i receive on my ATMEGA32L is not correct,for that i am using LED indication, when i am getting correct byte the LED should goes to glow, is anything wrong or required on TTL side,i.e PULL UP resistor or something else.
Ajay
Jul 7 2008, 8:12 AM
why are you looping? you can send and receive from PC to test the 2-way communication. may i know the purpose of your test project.
Please do post the code to see the problem properly.
Please do post the code to see the problem properly.
sashijoseph
Jul 7 2008, 8:04 PM
@MATHIVANAN
Are the baud rates set up correctly on both sides.
Try once with a true serial port on the pc instead of the usb-rs converter.
Are the baud rates set up correctly on both sides.
Try once with a true serial port on the pc instead of the usb-rs converter.
MATHIVANAN
Jul 15 2008, 9:07 PM
I tried on True Serial port and Baud rates are correct
Ajay
Jul 16 2008, 8:38 AM
hi mathivanan, i guess you replied almost after 1 week
i am really out of mind what was the exact point of discussion and what was the real problem. So if you dont mind..
i am really out of mind what was the exact point of discussion and what was the real problem. So if you dont mind..MATHIVANAN
Jul 17 2008, 5:24 AM
I want to know is there any special fuse settings is available for TXN RXN .
Ajay
Jul 17 2008, 8:13 AM
in the cable? no for sure..
pdi33
Jul 17 2008, 8:53 PM
hi Mathi,
check if ur control registers are correctly initialised.
if ur using the RX complete interrupt, then the RXCIE bit of the UCSRB register should be set along with the RXEN bit.
and no, there are no fuse bits related to transmission/reception in the atmega 16/32. I have checked both transmission/reception@ 8mhz internal oscillator and they work just as fine without programming any additional fuse bits.
.
check if ur control registers are correctly initialised.
if ur using the RX complete interrupt, then the RXCIE bit of the UCSRB register should be set along with the RXEN bit.
and no, there are no fuse bits related to transmission/reception in the atmega 16/32. I have checked both transmission/reception@ 8mhz internal oscillator and they work just as fine without programming any additional fuse bits.
.MATHIVANAN
Jul 17 2008, 11:34 PM
Thank you very much experts i am going to try.......more