Mar 12, 2004 Is it possible to connect 1 x input shift register and 2 x output shift registers simultaneously to hardware SPI, using only 4 IO lines? I would like to read 2 x 8 bits (8 switches) while writing 2 x 8 bits (16 LEDs). Please see attached schematics. 74HC595 and 74HC165 are used for output/input.
l'meters making use of Atmega328 as a get good at in SPI conversation with a one slave. Is there a way to avoid making use of the SS (slave choose) pin for SPI? That pin number can also be used for PWM result, which I would like to make use of.
AndréasAndreas
$éndgroup$4 Answers
Whéther or not you can link a SPI slave't 'select' input permanently energetic depends on both the particular slave and the general system style. Some slaves depend on edges on their select advices for issues like circulation control and/or byte positioning.
In some systems, in which the grasp and slave are usually often reset together (y.gary the gadget guy., via power cycling) and certainly not encounter clock glitches, you can obtain away with it, but it can be safer (even more reliable) to plan to include an active slave choose in your style.
Davé Tweed♦Dave TwéedATmega will be a master right here, as you yourself said.
Allow's consider a appearance at what the datasheet says about slave select flag:
As yóu can see, it's just utilized when ATmega will be a slave. Whén it's á expert, you use regular GPIO pins to choose a slave. There's even a paragraph abóut that in thé datasheet as well:
When configured as a Grasp, the SPI interface has no automatic handle of the SS range. This must be handled byuser software program before conversation can start.ln common, energetic slave go for range should end up being used. Slave go for series should activate slave before starting transmission and deactivate it after completing communication. Any free of charge pin number on the ATmega can end up being utilized for this objective.
AndréjaKoAndrejaKo
17.3k2121 gold badges9090 silver badges169169 bronze badges
$endgroup$$begingroup$The expression 'SPI' is certainly utilized to describe a broad variety of protocols where a expert device communicates with one or even more slave devices. A common scheme can be for a slave device to have got a 'go for' collection which is certainly true at the begin of each transaction and released at the finish of it. When making use of such an technique, the go for line serves the dual objective of synchronizing byte limitations and furthermore suggesting where 'commands' start and finish. When communicating with like a slave, it will be essential to have got one of the get good at's output pins linked to the slave-select wire, but any flag may end up being used for that purpose.
Some various other SPI slaves make use of different strategies for synchronization. Thére's no conceptuaI reason why slaves should require to use a go for cable, but numerous of them do. Unless you are usually developing the slave, the need for the go for cable will end up being identified by the sIave itseIf.
supércatsupercat38.7k11 silver badge65
65 metallic badges114114 bronze badges$endgroup$$begingroup$In my encounter on a current task without Slave select pin, you should create methods to verify synchronization/desynchronization between expert and slave. Like ás: CRC in hardwaré, Checksum in software program, fixed dimension packets, and include delay between packets só the slave cán course of action the last box before getting data available to the get good at gadget. Every time a desynchronization happens slave must réset the SPI device and waits at minimum the time between packets to acknowledge information. After these factors, I would suggest that you wear't use SPI without sIve select because yóu are going end up including too very much complexity on something quite easy: determining a GPIO pin number on the get good at as Chip SeIect.
FiIipe CalasansFiIipe Calasans
$éndgroup$