Forum Discussion

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

Spi_slave_to_avalon_mm + qsys + pio

Hi!

I try to implement very simple design using QSYS. It's SPI to GPIO converter (it's just a part of much more complicated design). I just want to control some GPIOs sending appropriate command via SPI . In QSYS I added SPI_SLAVE_TO_AVALON_MM_MASTER_BRIDGE which is connected to PIO. PIO is configured as 8-bit output register. QSYS automatically set the PIO's base address to 0x00 - 0x1f. I attach a screen-shot with a view of design from QSYS.

Now the problem is that I can't find in "Embedded Peripherals IP" documentation what I exactly have to send via SPI to set PIO outputs in appropriate state.

I know that in order to set any of the outputs to 1 or 0 I have to write to "Data" register(offset = 0) of PIO. In "Embedded Peripherals IP" documentation I found a very short example of "Bits ti AVALON-MM Transaction". But I don't understand what are "escape characters"(0x4D) for? What are "Idle characters"(0x4A) for?

And what about an address where I have to send the data? The base address that QSYS assigned to PIO is 0x00 and offset of "data register" is 0 so is the data reg address 0x00 + 0 = 0x00? Or am I wrong?

I would appreciate any help.

Kind regards,

Krzysiek :-)

2 Replies

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

    --- Quote Start ---

    But I don't understand what are "escape characters"(0x4D) for? What are "Idle characters"(0x4A) for?

    --- Quote End ---

    Idle is a control character which is transmitted when there's actually no data to be transmitted, so the receiver simply drops it.

    Clearly if you need to transmit 0x4A data you can't do it directly, since it would be dropped by receiver. Then the escape code is used to bypass this limitation.

    Whenever data matching a control code is to be transmitted, you must actually transmit a 2 code sequence, the escape code and the data XORed with 0x20

    Since 0x4D is itself a control code, you eventually must escape both 4A and 4D codes.

    Example:

    data not a control code : transmit as is

    data=any control code : transmit escape code, followed by (data XOR 0x20)

    0x4A : transmit 0x4D + 0x6A

    0x4D : transmit 0x4D + 0x6D

    Receiver knows this rule and will decode escape characters and retrieve the original data
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    @Cris72

    Thank You for your answer.

    As PIO has base address 0x00 to 0x1f (32 addresses) and "data register" has offset = 0, then the address of "data register" is still 0x00?

    What about the whole frame that I have to send (let's say that I want to enable 4 out of 8 outputs)?

    Will it be?

    4A 7A(Start of packet) 00 00 00 00(cmd) 00 00 00 00(addr) 00 00 00 7B(End of packet) 0F (data)

    CMD: 00 00 00 00

    ADDR: 00 00 00 00

    DATA: 00 00 00 0F (enable 4 out of 8 outputs)

    Regards,

    Krzysiek