SPI SLave

Droopy
Benutzer
Avatar
Gender:
Age: 58
Posts: 24
Registered: 01 / 2016
Subject:

SPI SLave

 · 
Posted: 10.08.2017 - 00:06  ·  #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
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: SPI SLave

 · 
Posted: 14.08.2017 - 14:24  ·  #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
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Re: SPI SLave

 · 
Posted: 14.08.2017 - 14:42  ·  #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
Gender:
Age: 58
Posts: 24
Registered: 01 / 2016
Subject:

Re: SPI SLave

 · 
Posted: 17.08.2017 - 14:03  ·  #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
Gender:
Age: 24
Posts: 1372
Registered: 03 / 2005
Subject:

Re: SPI SLave

 · 
Posted: 17.08.2017 - 15:19  ·  #5
Hi Peter.

Another option might be the SC16IS750 chip, which converts I2C to UART. That might avoid the extra complications.
Droopy
Benutzer
Avatar
Gender:
Age: 58
Posts: 24
Registered: 01 / 2016
Subject:

Re: SPI SLave

 · 
Posted: 17.08.2017 - 23:04  ·  #6
Thnx Merlin.

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

Peter
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   109   123 · Page-Gen-Time: 0.020662s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI