background image

 

AVR350 

1472D-AVR-01/08 

7 Modifications to Receive Protocol 

Users may wish to count how many “C’s” were sent during synchronization and after 
“n” number of tries abort the receive attempt. For embedded applications it’s not 
mandatory to have a 128-byte packet. You could have 64, 32, or even a 16-byte 
packet. The sender of course would have to comprehend this.  

If users do not wish to use the CRC method of data verification, simply replace 
sending a “C” for synchronization with a NACK instead. The sender will then send 
only the simple checksum of the data packet. Of course, the buffer size decreases by 
one and data errors may occur. This modification would allow communication with 
equipment that supports only the checksum method of data verification. 

8 Software 

Routines were compiled using IAR Workbench version 4.11A with high optimization. 
The software was tested using Hyperterminal at baud rates up to 115.2K. The 
receiver expects 8 start bits, 1 stop bit, and no parity bits. 

The STK500 starter kit is used as a test platform for an ATmega88 running from its 
calibrated 8MHz internal RC oscillator. This is sufficiently accurate at room 
temperature for operation up to 38.4K Baud. For higher Baud rates the on-board 
3.6864MHz oscillator or a 7.3728 MHz crystal should be used, with the init routine 
modified to properly set up the UART baud rate register UBRR0. Wait loops in the 

sendc

 and the 

recv_wait

 routines would also need modification. 

To verify proper operation of this code on the STK500, connect: 

  PD0 to ‘RS232 SPARE’ RXD. 

  PD1 to ‘RS232 SPARE’ TXD. 

  PD2 to switch SW0. 

Refer to the STK500 user manual for jumper locations and definitions. Connect a 9-
pin serial cable from a PC to the STK500 “RS232 SPARE” port, turn on power and 
use SW0 as a start of reception signal. Use an ATmega48/88/168 fitted to socket 
SCKT3200A2 to execute the code. 

Table 8-1. 

Protocol Flow Control 

Name 

Size in Bytes 

Function 

calcrc 

46 

Calculates 16-bit CRC 

init 

36 

 Low-level Hardware Initialisation 

purge 

50 

Reads UART Data Register for One Second 

receive 

52 

Main Receive Routine 

recv_wait 46 

Waits until Buffer Full Flag is Set or One 
Second Timeout 

respond 

56 

Sends an ACK or a NACK to the Sender 

sendc 100 

Sends an ASCII “C” Character to the Sender 
until the Buffer Full Flag is Set 

timer1 14 

Timer1 

Interrupt 

uart 

96 

Uart Receive Interrupt 

validate_packet 

136 

Validates Senders Packet 

xmodem 42 

Main 

Summary of Contents for AVR AVR350

Page 1: ...s than 1K Bytes of Code Space C High level Language Code 1 Introduction The Xmodem protocol was created years ago as a simple means of having two computers talk to each other With its half duplex mode...

Page 2: ...132 133 Start of Header Packet Number Packet Number Packet Data 16 bit CRC 3 Definitions The following defines are used for protocol flow control Table 3 1 Protocol Flow Control Symbol Description Val...

Page 3: ...self correcting after the receiver NACKs the sender 6 Data Flow Diagram The data flow diagram below simulates a 5 packet file being sent Table 6 1 Data Flow Diagram Sender Receiver C Times Out after T...

Page 4: ...scillator This is sufficiently accurate at room temperature for operation up to 38 4K Baud For higher Baud rates the on board 3 6864MHz oscillator or a 7 3728 MHz crystal should be used with the init...

Page 5: ...9 3 recv_wait c initialize timer1 counter for a 1 second delay wait till buffer is full or timeout 9 4 respond c clear error flags If packet was good or end of transmission then Send an ACK Else Purge...

Page 6: ...cond character in buffer plus the third character in buffer 0xff then compute CRC on packet data if CRC ok then increment packet number packet good else packet bad else bad packet number checksum else...

Page 7: ...ARRANTY RELATING TO ITS PRODUCTS INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTY OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE OR NON INFRINGEMENT IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIR...

Reviews: