Analog Devices DSP och frågetecken kring SPI

PIC, AVR, Arduino, Raspberry Pi, Basic Stamp, PLC mm.
Hillman
Inlägg: 64
Blev medlem: 25 januari 2006, 09:22:20
Ort: Västerås

Analog Devices DSP och frågetecken kring SPI

Inlägg av Hillman »

Stötte på en lite konstig grej och har kontaktat ADs support men ännu inte fått något svar efter två dagar så jag tänkte se om någon här har stött på samma problem.

Jag kör med en BF516F DSP från analog devices och har ett par SPI-enheter kopplade till den. Det har fungerat ok men nu skulle jag lägga till en accelerometer, ADXL345, också den från analog devices. Enligt accelerometerns datablad ska CPOL = 1 och CPHA = 1, tvärtom vad de andra enheterna kör. För att göra det enkelt kommenterade jag bort de andra enheterna i koden och mätte med oscilloskop för att se att det svarade som det skulle. Fick få följande konstiga fenomen.
Bild
CPOL = 0, CPHA = 0, allt ser ok ut men fungerar inte eftersom ADXL345 ska ha CPOL = 1, CPHA = 1

Bild
CPOL = 1, CPHA = 1. Istället för att vända på clock phase (CPHA) så inaktiveras chip select.

Kollar man i adi_spi_int.pdf, vilket är manualen till det bibliotek jag använt så hittar man följande:

5.4.3. Device Driver Specific Commands
• ADI_SPI_CMD_SET_CLOCK_PHASE
o Sets the transfer format
o Value = TRUE - beginning toggle, FALSE - middle toggle

Längre bak i manualen hittar man också:
6.2. Default Settings
item - Clock phase
default value - 1(slave select controlled by SW)
possible value - 0(slave select controlled by HW)
Command ID - ADI_SPI_CMD_SET_CLOCK_PHASE

Min fråga till analog devices var vad som egentligen gällde, om ADI_SPI_CMD_SET_CLOCK_PHASE styr chip select, som i mitt fall, hur styr jag då CPHA (clock phase)?

Någon här som vet?
Hillman
Inlägg: 64
Blev medlem: 25 januari 2006, 09:22:20
Ort: Västerås

Re: Analog Devices DSP och frågetecken kring SPI

Inlägg av Hillman »

Fick svar från Analog Devices support, verkar tyvärr inte finnas någon riktigt enkel lösning. Förstår inte riktigt hur deras förklaring ska lösa problemet eftersom CPHA=1 inte byter flank på klockan alls utan bara tar bort chip select. Hur byter jag flank på klockan? Har jag missförstått något?

Thank you for your question concerning the SPI slave select. It is true that the clock phase control bit is use to manage whether data is sampled on the leading or trailing clock edge. But this bit is also used to manage whether the slave select output bit is managed by hardware or software. These two attributes are sometimes in contention.

We are tracking a feature request (TAR-45231) to augment our SPI device driver to support a software select mode, but this enhancement has not been scheduled. The reason this is a problem is that one of the Blackfin SPI hardware controller slave select mode control bits is overloaded in functionality with the clock phase control bit (CPHA). A related problem is that in hardware slave select mode, the select line is toggled between bytes which can cause an unintentional slave device reset.

The detailed description of this problem is as follows:

Most Blackfin SPI hardware implementations provide both serial clock phase (CPHA) and serial clock polarity (CPOL) control bits within the SPI_CTL control register. These two serial clock control bits configure the SPI protocol to use one of four industry standard SPI clocking modes to suite external slave device clocking requirements.

However, the serial clock phase (CPHA) control bit happens also control programming of the slave select pins to be generated automatically by the SPI hardware (CPHA=0) or by application software (CPHA=1) directly manipulating an explicit flag pin around each SPI transfer. This is referred to as hardware/software slave select mode.

The hardware slave select mode (CPHA=0) deasserts and reasserts the slave device select line between each byte transfer. On some slave devices, deasserting the slave select in this way results in a slave reset and can interfere with a block transfer.

In cases where the slave device serial clock mode requires use of CPHA=0 on the Blackfin SPI master-mode controller (implying use of the hardware slave select mode), the slave reset between bytes can be avoided by using the needed hardware select (CPHA=0) mode coupled with a software-driven slave select technique. This solution requires the hardware slave select line not be enabled in the function enable register (FER) for the port and pin in question and that application software take full responsibility for driving the slave select pin as if CPHA=1 (software slave select mode) were active.

The workaround is to program the slave select pin "manually" (via the flag service) and manipulate the select before and after each transaction (DMA or otherwise). Assert the select just prior to the SPI enablement and deselect it at the transaction completion or DMA interrupt.

Regards,
Processor Tools Support
Batman
Inlägg: 97
Blev medlem: 11 december 2010, 15:05:42
Ort: Umeå

Re: Analog Devices DSP och frågetecken kring SPI

Inlägg av Batman »

Gissar att du kör med VisualDSP? Har själv bara kört med deras gcc toolchain så jag kan inte kommentera den.
CPHA kontrollerar både flank och hårdvaru chip select automatiken.
ADSP-BF51x Blackfin Processor Hardware Reference har bilder på hur CPHA påverkar flanken, se t.ex. figure 17-5, 17-6, och 17-7.
När du valt CPHA så du får den flank som passar din slave, får du anpassa chip select metod beroende på vad CPHA blev.
Skriv svar