Reversing SPI shift out order on Microblaze design

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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


Re: Reversing SPI shift out order on Microblaze design

Quoted text here. Click to load it


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&0xaa)>>1);
x= ( (x&0x33)<<2) | ((x&0xcc)>>2);
x= ( (x&0x0F)<<4) | ((x&0xF0)>>4);

Whichever pelases you most

Zara

Re: Reversing SPI shift out order on Microblaze design
Quoted text here. Click to load it
-------------------------------------------------------------------------------------------------------------------------
Quoted text here. Click to load it
-------------------------------------------------------------------------------------------------------------------------
Quoted text here. Click to load it

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] <= dataIn[0:7];

Of course, you could just have it always connected:

assign DataOut[7:0] = DataIn[0:7];

Write it to DataIn, send it to SPI from DataOut.

Cheers

PeteS


Re: Reversing SPI shift out order on Microblaze design
Quoted text here. Click to load it

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


Site Timeline