Page 1 of 1

A more friendly way to create a chip select with SPI ?

Posted: Mon May 05, 2008 9:46 pm
by mhiernau
Dear all,

I'm trying to do a very simple thing : send some SPI to a peripheral (see model attached). The thing is that the peripheral needs its CS to be pulled down just before the transfer and pulled back up at the end. To do this, I used the block ordering function, but I had to introduce a lot of NOPs. The SPI block orders the next block as soon as it has transmitted the send request to the SPI peripheral, it does not wait for the transfer to be effectively over.

The current method works, but I wondered if there was a more CPU friendly way, as this is quite ressource consuming.

Thanks,
Martin

Re: A more friendly way to create a chip select with SPI ?

Posted: Mon May 05, 2008 11:32 pm
by LubinKerhuel
Hi Martin,

This is your original solution:
Original
Original
interfacage_SPI_original.png (2.65 KiB) Viewed 9534 times
The first solution I propose is to disable the Chip first, and enable it just after...
Solution 1
Solution 1
interfacage_SPI_Sol1.png (2.58 KiB) Viewed 9531 times
The second solution I propose is to configure the SPI read/write so as to read and write a data. In this way, the SPI block waits for the SPI communication to finish.
Solution 2
Solution 2
interfacage_SPI_Sol2.png (2.58 KiB) Viewed 9533 times
Here is the model with the three solutions. These are not going to work all together. Delete at least two solutions!
interfacage_spi_b.mdl
Simulink model
(39.92 KiB) Downloaded 573 times
I corrected mistakes about sampling time. I strongly recommend using the "sample time color" option of simulink!

Lubin
PS : I see that you were inscribed to the forum. You should loggin to the forum before writting message. It allows to get mail when a response is given and other usefull options ( also less administration task for me...)

Re: A more friendly way to create a chip select with SPI ?

Posted: Tue May 06, 2008 1:49 pm
by mhiernaux
Hi Lubin,

Thanks for your reply.

I tried the 2 options, but I think I'm doing some mistakes as the CS goes back to disable state in your last option, before all bits are effectively transmitted. The 2nd option is working but is less optimal for me, as the CS disable commands the latch of my SPI DAC, and thus is happening 1 cycle later here.

Any ideas ?

Thanks,
Martin

Re: A more friendly way to create a chip select with SPI ?

Posted: Tue May 06, 2008 8:54 pm
by LubinKerhuel
Try to check "Wait for incomming data (slave mode)" and uncheck "Wait for previous operation to finish, and reset before read".
The block menu is not very clear yet. I'll try to make it more clear in the next version...