Reversing SPI shift out order on Microblaze design

Oct 20, 2006 3 Replies

Hi, I have a design that connects a Spartan 3e running a Microblaze soft-core with an SPI unit attached to the OPB bus to a 16 Bit DAC unit (DAC8534). The data I send to the DAC unit has the bit order reversed. The SPI_OPB pheripheral has no way of reversing the shift out order from what I can see. Below is a program snippet of sending data to the dac unit:



------------------------------------------------------------------------------------------------------------------------- // Select the DAC Unit XSpi_mSetSlaveSelectReg(XPAR_SPI_DAC_BASEADDR, SPI_DAC_SELECT);



// Set the message data. send_data[0]=0x20; // Control Register send_data[1]=0x0F; // Upper 8 bit value send_data[2]=0x0F; // Lower 8 bit value



// Send the message data. spi_transfer(send_data, 3);



// Deselect the DAC Unit XSpi_mSetSlaveSelectReg(XPAR_SPI_DAC_BASEADDR, SPI_NONE_SELECT);



-------------------------------------------------------------------------------------------------------------------------



The data sent to the dac unit appears as 0xF0F0 instead of 0x0F0F disregarding the control byte. Does anyone know of how I can reverse the bit order at a minimal overhead cost. Can you give an example of bit order reversing?



Thanks, Aaron Curtin



You may use a look-up table of 256 bytes.

Or you may use two look-up tables of 16 bytes, one for low nibble and one for high-nibble

Or you could use the trick of intergchanging adjacebts bits, then bit pairs...

x= ( (x&0x55)1); x= ( (x&0x33)2); x= ( (x&0x0F)4);

Whichever pelases you most

Zara

-------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------

Is the SPI selecting the correct register?

If it was a consistent issue, then the register would also be reversed, one might think (so in your snippet you would address 0x04 for bit reversal).

Interesting.

A simple (very simplistic) bit order reverser (single cycle) would take

8 regs plus maybe a LUT.

Something like

reg [7:0] DataIn; reg [7:0] DataOut;

... in some always block

DataOut[7:0]

I can't see a parameter for reversing the bits either.

The source for opb_spi is in c:/EDK81/hw/XilinxProcessorIPLib/pcores/opb_spi_v1_00_d/ Copy it to your local pcores directory and modify it. Then use your local copy.

Alan Nishioka

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required