How i can exchage information using SPi master with Firmware Controlled Slave Selects?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello Every one,

   

I want to begin a communication between SPI master and two slaves. I wonder how i can do "Firmware Controlled Slave Selects" or using control registers.

   

Looking forward for reply!

   

Awais

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Just use two strong output pins without hardware connection named alike SS1 and SS2 (or whatever you prefer). When a transaction starts, biringing the corresponding SS-line low by issuing a SS1_Write(0) (or more readable SS1_Write(SelectSlave)) and when all data has been sent out issue a SS1_Write(1) (or SS1_Write(DeselectSlave)).

   

Do not forget to #define SelectSlave 0 and DeselectSlave 1.

   

Pitfall is: when there is still a byte or part of it in the transmit buffer de-asserting the SS will clobber the communication. So really wait for transmission completed.

   

 

   

Bob

View solution in original post

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Just use two strong output pins without hardware connection named alike SS1 and SS2 (or whatever you prefer). When a transaction starts, biringing the corresponding SS-line low by issuing a SS1_Write(0) (or more readable SS1_Write(SelectSlave)) and when all data has been sent out issue a SS1_Write(1) (or SS1_Write(DeselectSlave)).

   

Do not forget to #define SelectSlave 0 and DeselectSlave 1.

   

Pitfall is: when there is still a byte or part of it in the transmit buffer de-asserting the SS will clobber the communication. So really wait for transmission completed.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thankyou Bob for your reply.

   

Please see the picture attach. Is this the correct thing that you just suggested.

   

Looking forward for your reply

   

Regards

   

Awais

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

"Is this the correct thing that you just suggested"

   

Nearly.

   

You can omit the control registers, remove the "Hardware Connection" of the pin components and directly write to the pin using

   

SPI_SS_Master_DAC_Write(0); // Select DAC

   

or

   

SPI_SS_Master_DigPot_Write(0);// Select DigPot

   

This is saving some resources.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Perfect!

   

One more thing Bob, If i want to do this using control register. Then in the data sheet it says "The control register is used to control the slave select output. Before starting the transfer, the control register must be written to the active slave select line, and then returned to the inactive state after the transfer has been completed." The bold sentence is making me confused. Can you elaborate it?

   

 

   

Looking forward for your reply!

   

Regards

   

Awais

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

"Then in the data sheet it says... " Have you got a link to the datasheet?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I attached the document(data sheet). It's on page 4.

   

 

   

Awais

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The pin component already has got an internal buffer to store the information, so using a control register is a bit overdone. Probably Cypress choose that to make things more clear for the first-time users.

   

Before you start an SPI transaction bring the ss-line low to address the slave. When the transaction is complete, which you can see by examining the number of bytes received, you bring the corresponding ss-line high again. That is done by issuing a SS_Write(HiLoState).

   

 

   

Bob

0 Likes