Yahoo Groups archive

AVR-Chat

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

Thread

Sending multi-bytes sequence throgh SPI (AVR-Bascom)

Sending multi-bytes sequence throgh SPI (AVR-Bascom)

2005-08-23 by behrooz_hariri

Hi. In spi between two AVR, the data sequence which is important to 
realize what byte is for temperature for example, and what was 
indicating humidity, becomes corrupted when I reset the slave. How 
can I distinguish in slave (receiver) which byte was sent first and 
wich was the next?

in master:
A(1) = "a"
A(2) = "b"
A(3) = "c"
Do
...
Spiout A(1) , 3 
Loop

--------
in slave:
Do
Spiin A(1) , 3 
print A(1) ; A(2) ; A(3)
Loop

I deliberately resset the slave and want to receive the same 
sequence but I receive: 
a , c, b
c, a, b
or ther sequences.

I need to receive 'a' as A(1), 'b' as A(2) and 'c' as A(3).
What is the solution?
Tnx in advance for your help.

Behrooz Hariri

Re: [AVR-Chat] Sending multi-bytes sequence throgh SPI (AVR-Bascom)

2005-08-24 by Thomas Keller

On Tue, 2005-08-23 at 12:05 +0000, behrooz_hariri wrote:
> Hi. In spi between two AVR, the data sequence which is important to 
> realize what byte is for temperature for example, and what was 
> indicating humidity, becomes corrupted when I reset the slave. How 
> can I distinguish in slave (receiver) which byte was sent first and 
> wich was the next?
> 
> in master:
> A(1) = "a"
> A(2) = "b"
> A(3) = "c"
> Do
> ...
> Spiout A(1) , 3 
> Loop
> 
> --------
> in slave:
> Do
> Spiin A(1) , 3 
> print A(1) ; A(2) ; A(3)
> Loop

   You'll need to send some form of synch flag first, then the data in
the order in which you have decided to send it.  The receiver should not
stoire any data until it has properly decodded the synch flag.

   A synch flag can be any byte or combination of bytes you wish.  For
example, if you're transfering 3 bytes of datam and they can eachor any
of them can hold values between 00 and ff, then your synch should be a
multiple of bytes, such that the same sequence can never occur as data
(e.g., 4 FFs, or FF 00 FF 00, or whatever).  once your receiver has
logged a synch event, then it can start receiving and counting data
bytes.

Tom

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.