Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Bidirectional SPI switch?

This is a complex problem which I am very unsure of, the basic idea is that I want code that switches between 3 SPIs.

I was startled when I noticed the statement that I was about to write

A_SCLK <= C_SCLK

C_SCLK <= A_SCLK

both are true, but this would induce registers, all I want is a wire connection.


-- The idea is that choose either A or B is exclusively
-- connected to C
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity bidir_SPI_switch is
    port(
        A_SCLK, B_SCLK, C_SCLK        :    INOUT STD_LOGIC;
        A_SOMI, B_SOMI, C_SOMI        :    INOUT STD_LOGIC;
        A_SIMO, B_SIMO, C_SIMO        :    INOUT STD_LOGIC;
        A_CSn, B_CSn, C_CSn    :    INOUT STD_LOGIC;
        en, S    : IN BIT
    ); 
end bidir_SPI_switch;
architecture behaviour of bidir_SPI_switch is
    process(en,S)
    begin
-- MASTER enable
        if en = '0' then
            A_SCLK                   HOW??
            C_SCLK
        else
-- SELECT either A or B
        end if;
    end process;

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Couldn't make full sense of what was happening. However, it did simulate it well.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This has been unsuccessful, it seems nothing is going through the switch.

    Is there an example code out there that shows how to build a Bidirectional bus and the assumptions required of the entities that connect to it.

    This is doing me head in.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    In my opinion, the problem is a lack of clarity about the required prerequisites of a bidirectional "switch". A FPGA doesn't offer bidirectional bus switches of analog switch type. It can implement bidirectional buffers, similar e.g. to a 74HC245, that however need a control signal to decide about the actual data direction.

    You have to find out, how this direction information can be deterrmined.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks FvM, I've added an extra pin in the design for direction and now it works fine in simulation with the bigger design.