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

Post Reply
mhiernau

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

Post by mhiernau » Mon May 05, 2008 9:46 pm

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
Attachments
interfacage_spi.mdl
Model with CS
(31.77 KiB) Downloaded 530 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

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

Post by LubinKerhuel » Mon May 05, 2008 11:32 pm

Hi Martin,

This is your original solution:
Original
Original
interfacage_SPI_original.png (2.65 KiB) Viewed 9512 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 9509 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 9511 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 572 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...)

mhiernaux
Posts: 5
Joined: Mon Apr 28, 2008 8:16 pm

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

Post by mhiernaux » Tue May 06, 2008 1:49 pm

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

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

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

Post by LubinKerhuel » Tue May 06, 2008 8:54 pm

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...

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests