So I currently have a bit banged 8-bit parallel protocol where the host puts data on 8 data lines (value of 5 for this specific problem) then raises STROBE to notify the device (Pi Pico) there is data to read. This works and if you hook a logic analyzer up to it, it behaves as expected. So I was looking to speed up the protocol by implementing the protocol in PIO. I think I have correct PIO code, but I could have completely screwed it up too as I am brand new to PIO. Code is below.
So I had it running and the receive flow portion of the PIO seemed to work, but the data value pushed to the RX FIFO was always zero, not 5. So I hooked up the logic analyzer and all of the data lines are pinned to 0 when STROBE went high (not 5). I re-flashed with the bit banged IO version and everything acted normally. I have no idea why this would be the case. Okay I sound like a crazy person at this point, but I am out of ideas. Any ideas would be greatly appreciated. Thanks
So I had it running and the receive flow portion of the PIO seemed to work, but the data value pushed to the RX FIFO was always zero, not 5. So I hooked up the logic analyzer and all of the data lines are pinned to 0 when STROBE went high (not 5). I re-flashed with the bit banged IO version and everything acted normally. I have no idea why this would be the case. Okay I sound like a crazy person at this point, but I am out of ideas. Any ideas would be greatly appreciated. Thanks
Code:
.program parallel_io.side_set 1 optnop side 0jmp pin, recv // High means STROBE is HIGH and host is sending datajmp !OSRE,sendjmp exitsend:wait 0 gpio 11 // Wait for DIRECTION to go LOW set pins 1 // Set 74LVC245_DIR HIGH (A to B) for send mov osr, !null // Set data pin direction to OUTPUTout pindirs, 8out pins, 8 // Output data nop side 1 // Set ACK HIGHwait 1 GPIO 12 // Wait for STROBE to go HIGHnop side 0 // Set ACK LOWwait 0 GPIO 12 // Wait for STROBE to go LOWjmp exitrecv:set pins 0 // Set 74LVC245_DIR LOW (B to A) for recvmov osr, null // Change Direction of data pinsout pindirs,8 in pins 8 // Read data pinspushnop side 1 // Set ACK HIGHwait 0 gpio 12 // Wait for STROBE to go LOWexit:nop side 0 // Set ACK LOW% c-sdk {#include "hardware/clocks.h"#include "hardware/gpio.h"static inline void parallel_output_program_init(PIO pio, uint sm, uint offset) { pio_sm_config c = parallel_io_program_get_default_config(offset); // IO mapping sm_config_set_out_pins(&c, 0, 8); sm_config_set_in_pins(&c, 0); sm_config_set_set_pins(&c, 10, 1); sm_config_set_sideset_pins(&c, 13); sm_config_set_jmp_pin(&c, 12); pio_sm_set_pindirs_with_mask(pio, sm, 0xFF, 1u << 10 | 1u << 13); pio_sm_set_pindirs_with_mask(pio, sm, 0x00, 1u << 11 | 1u << 12 | 0xFF); pio_sm_set_pins_with_mask(pio, sm, 0x00, 1u << 13 | 1u << 10); for(int i = 0; i < 8; ++i) pio_gpio_init(pio, i); for(int i = 12; i < 14; ++i) pio_gpio_init(pio, i); sm_config_set_out_shift(&c, true, true, 8); pio_sm_init(pio, sm, offset, &c); pio_sm_set_enabled(pio, sm, true);}static inline void parallel_io_putc(PIO pio, uint sm, char c) { pio_sm_put_blocking(pio, sm, (uint32_t)c);}static inline char parallel_io_getc(PIO pio, uint sm) { return pio_sm_get_blocking(pio, sm);}static inline bool parallel_io_has_data(PIO pio, uint sm){ return !pio_sm_is_rx_fifo_empty(pio, sm);}%}
Statistics: Posted by zoggins — Wed Jul 03, 2024 4:07 am