Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

half duplex UART programming for Atmega32

Status
Not open for further replies.

mformazhar1980

Junior Member level 1
Joined
Mar 23, 2009
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
atmega32 uart

hi
i am heading to communicate a power drive unit(PDU) with Atmega32(USART), the power drive unit(PDU) supports one wire communication.
i select C programing on ATmel AVR studio. what i need is to write a C code for UART half duplex communication. can any body give me a small code as an example by considering the below mentioned details, so that i could be able to setup the communication for rest of the commands in packets.

i am bit confuse of making packet Format in C,as the byte format for this communication should be of 12bits
i.e the communication should be of:
Asynchronous
Half duplex
baudrate 38400
LSB first
Each bit= 26microSecond
1 start bit(0)
8 data bits
1 parity bit(even)
2 stop bits(1)

and the packet format that is used between (atmega32)UART and PDU is of as follows

the packet length depends on the packet type that is denoted by the first or header byte.
forexample the startup packet should look like this:
Startup packet should be of 2 bytes of 12 bits= 0.624mS (26microsecond per bit)
startupPacket Format:
___________________________________________________
Header : Hex 53,ASCII`S` 1 byte
___________________________________________________
Checksum 1 byte
___________________________________________________
@38.4kbps Total Size of packet 2 bytes

the last byte of the packet contains the packet checksum, which is calculated by summing the previous bytes of the packet and then 1`s complementing the answer.
the startup packet should be repeated every 10ms until the response from PDU received.
now my question is how do i make packets using c?
next is that as i never did UART programming before, considering the above senario how do i start writing a USART interface program for such communication?
thanks and looking forward for some good advice.

this is a small detail about the first packet i suppose to send to PDU for communication in response to this startup packet the PDU send a RESPONSE packet of 4 bytes:
i.e 4 bytes of 12 bits= 1.248mS (26microsecond per bit)

the Response pakect format looks like this:
___________________________________________________________
Header : Hex73,ASCII `s` 1 byte
___________________________________________________________
Lamp Spec : Voltage 1=12V,2=24V Bit 4-7 1byte
Wattage 0=5W,1=10W Bit 0-3
___________________________________________________________
Lamp Flags : Single bulb failure detection Bit7
0=disable , 1= enabled 1byte
Spare =0 Bit1-6
0= Non Dual Bit0
1= Dual
___________________________________________________________
check sum 1byte
______________________________________________________________
@38.4kps 1.248ms Total packet 4Byte



regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top