avreal synchronisation lost

Everything you wanted to know about,
but were afraid to ask.

As can be found in site log phrase “synchronisation lost” is one of most popular in site search, but no one asks the question in comments.

“synchronisation lost” message means programmer-to-microcontroller communication fault. SPI interconnection between programming adapter and microcontroller works in the same manner as between two microcontrollers.

spi-loop

Bytes shifted out by programmer (MASTER) are placed into microcontroller (SLAVE) shift register. If the bytes are not replaced by internal programming hardware they will be shifted out back to programmer.

For write commands the first byte of reply is the last byte of previous command and first three bytes of four-byte command are repeated on MISO output with one-byte delay.
For read commands the first two command bytes are echoed back in reply bytes 2 and 3 and the third command byte is replaced with byte read from microcontroller.

For example, Read Fuse High bits command data flow looks as

Direction Byte 1 Byte 2 Byte 3 Byte 4
programmer → controller 0x58 0x08 0x00 0x00
controller → programmer last byte of
previous command
0x58 0x08 fuse value

Some command and reply codes can be found in avreal output with -% switch.

Adapter enabled
	% Reset
	% PgmOn reply  FF FE 53 00
	% Synchronised after 1 try
	% GetID reply  00 30 00 1E
	% GetID reply  00 30 00 94
	% GetID reply  00 30 00 06
	% Read ID: 0x1E9406
Device connected, mega168|mega168A detected
	% Read Lock	command 58 00 00 00,  reply 00 58 00 FF
Chip not locked
	% Read Osccal	command 38 00 00 00,  reply 00 38 00 B0
	% Read Fuses	command 50 00 00 00,  reply 00 50 00 C2
	% Read Fuses	command 58 00 00 00,  reply 00 58 00 FF
	% Read Fuses	command 58 08 00 00,  reply 00 58 08 DD
	% Read Fuses	command 50 08 00 00,  reply 00 50 08 F9

Thus, bytes 2 and 3 of reply will be equal to bytes 1 and 2 of command when interconnection between programming adapter and microcontroller is synchronous.

If the bytes are not matched it means that the microcontroller goes out of programming mode or commands/replies in communicaton loop are corrupted. Anyway, it is not a good idea to continue programming because corrupted command can be interpreted, for example, as write fuse command with unwanted fuse value. That way in this case avreal exits with the message under discussion.

Entering programming mode works in the same way. The difference is that the first command byte does not echoed back to programmer because microcontroller is not in porgramming mode yet. The programming enable sequence is 0xAC 0x53 0x00 0x00. At the end of the second byte receiving the microcontroller goes to programming mode and 0x53 is echoed back in the third byte of reply. If the third byte is not 0x53 then a resynchronisation procedure must be made.

3. The Serial Programming instructions will not work if the communication is out of synchronization. When in sync. the second byte (0x53), will echo back when issuing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all four bytes of the instruction must be transmitted. If the 0x53 did not echo back, give RESET a positive pulse and issue a new Programming Enable command.

If in some tries 0x53 is not received in the third byte, avreal exits with Can’t resync message. The message is number two in “afraid to ask” question list.

The most probable causes of synchronisation failure are “dirty” interface signals by reason of bounces in signal and ground lines and SCK frequency near the top marging for given MCU clocking frequency. Check adapter hardware, cables, routing in the first case and lower SCK frequency by -o (-os) switch in the second one.

Leave a Reply

[flagcounter image]