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

mhiernau

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

Postby 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 165 times

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

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

Postby LubinKerhuel » Mon May 05, 2008 11:32 pm

Hi Martin,

This is your original solution:
interfacage_SPI_original.png
Original
interfacage_SPI_original.png (2.65 KiB) Viewed 1990 times


The first solution I propose is to disable the Chip first, and enable it just after...
interfacage_SPI_Sol1.png
Solution 1
interfacage_SPI_Sol1.png (2.58 KiB) Viewed 1987 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.
interfacage_SPI_Sol2.png
Solution 2
interfacage_SPI_Sol2.png (2.58 KiB) Viewed 1989 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 189 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 ?

Postby 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: Marseille - France
Contact:

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

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


Return to “dsPIC Peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest