Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)

VHDL SPI Interface

Altera_Forum
Honored Contributor II
1,897 Views

Hello, 

 

I made my own PCB with a Cyclone III, a simple DAC controlled with a SPI bus and I use Quartus II 10.1 with VHDL. 

 

The board is working but now i'm trying to connect to the DAC with a SPI bus. I would like to use the FPGA as master. 

 

Could someone please help me connecting to the DAC with SPI? 

 

Frans.
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
984 Views

Are you using a CPU such as Nios, or just HDL? 

There is a SPI master available in SOPC builder, but if you are making your own HDL, it may be easier to do your own SPI master. The SPI bus is one of the simplest serial buses that exist... you just have a clock, a select signal that must be valid during the transfer and a shift register that holds the data.
0 Kudos
Altera_Forum
Honored Contributor II
984 Views

Thank you for your reply, 

 

I will try to make my own VHDL program for a SPI bus. When I managed to do so, I will post it here so other people might find it usesful. 

 

Frans.
0 Kudos
Altera_Forum
Honored Contributor II
984 Views

Dear Daixiwen, 

 

I'm a hardware engineer having some difficulties programming my DAC with a shift register. Could you please help me find my way a little bit? 

 

I just need to transfer 16 bits serial. For example, how can I just put 1111 1111 1111 1111 on an output serially on a clock.
0 Kudos
Altera_Forum
Honored Contributor II
984 Views

You can find many examples of HDL SPI master / slave code with explanations just searching it on google.

0 Kudos
Altera_Forum
Honored Contributor II
984 Views

Something like below. For slower speed, the clock pin would be set in the code as well.  

signal sr : std_logic_vector (15 downto 0); //... if rising_edge(clk) then if load = '1' then sr <= data; else sr <= sr(14 downto 0) & '0'; end if; end if; out_pin <= sr(15);
0 Kudos
Altera_Forum
Honored Contributor II
984 Views

Thanks, 

 

I managed to get the DAC working but what is the meaning of: 

 

else 

sr <= sr(14 downto 0) & '0';
0 Kudos
Altera_Forum
Honored Contributor II
984 Views

it is a left bit shifting. You are replacing the 15 most significant bits from sr by its 15 least significant bits, and pad with an extra '0'.

0 Kudos
Reply