ARM9260 SPI chip select question - Page 1
Forum section: electronics / general

author: SuperJeep
author_rank: Contributor
timestamp: September 26, 2013, 02:19:18 pm
content: This may be a very chip specific question but hopefully some one has had experience with it.The AT91SAM9260 arm uC I am using has two SPI peripherals with 4 chip select lines each (spi1_npcs0-3, and spi0_npcs0-3). my question is: Can I setup the spi0 peripheral (clock and MOSI lines) but use the spi1 peripheral's chip select line? (the custom board is wired this way so I cant get around it). Would it be too "hack" to simply initialize the CS pin of the slave and pull it low manually before transmission? Its controlling a DAC which doesnt need data very often.I guess what I am looking for is -> Are the spi peripherals of this chip completely independent of one another on a hardware level and therefore not allowing me to use the clock lines of one with the chip select of another?I think my best option is to manually setup the CS pin as an output and pull it low when I want to transmit (unless I am missing something)EDIT:I just realized that what I am asking is for people to go through a huge datasheet and find information for me. I am going to attempt to solve my own problem and will post an update in case anyone needs this information in the future. As of now, it seems the peripherals are independent and manually pulling the CS pin low seems to be the best solution.

author: senso
author_rank: Frequent Contributor
timestamp: September 26, 2013, 06:18:44 pm
content: There is NO problem what so ever in using GPIO to control the CS lines, at least in the smaller atmegas, it works a treat, but be aware of one thing, in the atmegas, if the hardware CS pin of the SPI interface is used as an input pin it can set the SPI into slave mode.

author: dannyf
author_rank: Super Contributor
timestamp: September 26, 2013, 08:11:11 pm
content: Yes, it can be done.It is very easy to do it as a master.For a slave, you will need to have an interrupt on that pin. In the corresponding isr, turn on the spi module.

author: Harvs
author_rank: Super Contributor
timestamp: September 27, 2013, 01:21:04 am
content: Only other thing I can think of to consider (having not gone through the datasheet) is if you are using DMA, and the peripheral requires the CS pin to be cycled each transaction (like most? DACs) then on some mcus they can be configured to bring the CS line high between words automatically.This is only of significance really if your using an external DAC for waveform generation with DMA, or automatically sampling from an ADC. So probably of no significance in your case.

author: SuperJeep
author_rank: Contributor
timestamp: September 27, 2013, 03:35:55 pm
content: Thanks everyone for the advice and feedback. I actually ended up running into a bigger issue. I was unable to get the SPCK to run at all. Even after trying multiple ways and register settings for initializing the SPI peripheral it wouldnt work(made sure the pins were initialised to the peripheral and not gpio).I have resorted to using an interrupt based off of another timer in my code to manually generate the SPI clock and program the entire DAC by "bit-banging" each pin.One quick question. Is this entirely frowned upon? I only need to program this DAC a few times and there is a decent amount of time between these moments. so I could technically intialise the interrupt routine to generate the spi signals when needed and then disable it once the DAC is programmed.

author: TheDirty
author_rank: Frequent Contributor
timestamp: September 27, 2013, 05:47:45 pm
content: Bit banging SPI is very common and simple. Not frowned on at all.

author: dannyf
author_rank: Super Contributor
timestamp: September 27, 2013, 06:11:37 pm
content: QuoteNo reason to use a timer interrupt for that, unless you are truly emulating a hardware spi - ie., loading up the data register and the timer module will send the char by itself.Bit-banging is OK but tends to be considerably slower than hardware spi.

author: SuperJeep
author_rank: Contributor
timestamp: September 30, 2013, 01:42:56 pm
content: Thanks for the replies. I'm glad to hear that it, It makes sense that the only major benefit for using the peripheral is reduced cpu overhead and cleaner code but I think my case makes this fine seeing as I am only programming a dac to set a reference voltage output so I am not emulating an analog waveform or anything (speed isnt an issue).Thanks again for the help everyone