SPI SLave

Droopy
Benutzer
Avatar
Geschlecht:
Alter: 59
Beiträge: 24
Dabei seit: 01 / 2016
Betreff:

SPI SLave

 · 
Gepostet: 10.08.2017 - 00:06 Uhr  ·  #1
Hey all,

There is an easy spi master port in avrco, but is there also a simple spi slave driver in avrco for the xmega?
Someting similar like there is for the serport :
- an import were to configure the spi port (Slave, mode0..4, bit order)
- a tx buffer you can put data that is shift out if the spi master delivers the clock (interrupt based?)
- a rx buffer that is holding the bytes that were shifted in by the spi master (interrupt based?)

The setup I have is as follows:
An xmega with a spi master port that is connected to a LCD display with spi bus. On that same bus I need to connect a second xmega (working as slave). The load of the slave xmega is high but the communication between master and slave is minor.
(Taking other ports on the xmega is not an option)

Thanks for some help ;)

Peter
rh
Administrator
Avatar
Geschlecht:
Herkunft: Germany
Alter: 25
Homepage: e-lab.de
Beiträge: 5558
Dabei seit: 03 / 2002
Betreff:

Re: SPI SLave

 · 
Gepostet: 14.08.2017 - 14:24 Uhr  ·  #2
Hello Peter,
in my opinion an SPI slave makes no sense when implemented
in an uC. The SPI Master expects always an answer at the time
when he sends a request. So the slave must write the expected
answer into the SPI Tx register bevore the Master vsends a request.
ok, one can implement an overlaying protocol which reads the
first request and then responds in the second request.
But there is a fürther quirk when the Slave is not fast enough
and misses any request. Think of interrupts and multi tasking.

The setup of a Slave SPI is easy but the necessary overlaying
protocol is very dependend of the user program so there it isn´t
possible to build a generic driver in AVRco. Use one of the several
UARTs in the XMega and your are on the right side.

rolf
Merlin
Administrator
Avatar
Geschlecht:
Alter: 25
Beiträge: 1474
Dabei seit: 03 / 2005
Betreff:

Re: SPI SLave

 · 
Gepostet: 14.08.2017 - 14:42 Uhr  ·  #3
FWIW

I have created SPI slaves using MEGA (not XMEGA chips), and they worked very well, but Rolf is right in his concerns. The temptation is to run SPI as fast as possible, but if you are using MEGAs as slaves you actually need to run SPI as slowly as possible to get reliable operation - it should still be plenty fast enough. In fact I deliberately ran the master with a slow crystal just to make sure. This is not the way the AVRCo SPI master is implemented, and if I were doing it again I would, as Rolf suggests, use the UARTS.

In summary - been there, done that, wouldn't do it again.
Droopy
Benutzer
Avatar
Geschlecht:
Alter: 59
Beiträge: 24
Dabei seit: 01 / 2016
Betreff:

Re: SPI SLave

 · 
Gepostet: 17.08.2017 - 14:03 Uhr  ·  #4
Sorry for the late respons ;)

Thanks a lot for your info.
The information between master and slave avr is not a lot and can be slow. But like you suggest, the uart can also be used.
The only problem is that I wanted the LCD to be driven from the master avr and the LCD has only spi bus.
What I maybe can do, is use a uart connection between master and slave avr and connect the LCD to the slave avr trough spi bus.
The protocol over the uart than need to be expand with the communication for the LCD : the slave avr act like a uart/spi gateway between master avr and LCD.

Thanx all ;)
Merlin
Administrator
Avatar
Geschlecht:
Alter: 25
Beiträge: 1474
Dabei seit: 03 / 2005
Betreff:

Re: SPI SLave

 · 
Gepostet: 17.08.2017 - 15:19 Uhr  ·  #5
Hi Peter.

Another option might be the SC16IS750 chip, which converts I2C to UART. That might avoid the extra complications.
Droopy
Benutzer
Avatar
Geschlecht:
Alter: 59
Beiträge: 24
Dabei seit: 01 / 2016
Betreff:

Re: SPI SLave

 · 
Gepostet: 17.08.2017 - 23:04 Uhr  ·  #6
Thnx Merlin.

I gonna reevaluate the whole setup and verify all possibilities I have without the spi master slave ;)

Peter
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.
MySQL Queries: 15 · Cache Hits: 14   109   123 · Page-Gen-Time: 0.044261s · Speichernutzung: 2 MB · GZIP: ein · Viewport: SMXL-HiDPI