Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4501

General • Receive then send data in the same pin using PIO

$
0
0
I'm a real beginner in micro controller so I basically have no idea what I'm doing and just do things base on the documents I read.

Basically I'm trying to communicate on a device with its own protocol but the data transmitted is a 16bits uart rx and tx is sent by turn.
this is a 3 pin connection. Pico is acting as slave.

pin1 signals the start of transfer: Low start, High end
pin2 determines who is sending the data: High master is sending, Low slave is sending
pin3 is the data pin: 18 bits is transmitted by master and slave in turn, includes start bit, data and end bit
Baud rate is 115200 (I get inconsistent data when using this in divider that's why I don't use it)

I have no problem reading the data but I can't seem to send data. I used another one of my pico to analyze the data but I only see data sent by master. How do I switch the pin's direction properly to transmit data to the master device?

Code:

.program gbacom.define public SC_PIN 1.define public SO_PIN 2.wrap_target; Start receiving data    wait 0 gpio SC_PIN  ;wait start of transmission    wait 1 gpio SO_PIN  ;wait signal master transmitting    set pindirs, 0      ;set pin input    wait 0 pin 0 [4]    ;[start bit] set x, 31 [28]start_bit:nop [30]            ;just to skip start bitjmp x-- start_bit   ;start bit end    set y, 15           ;read 16 bitsloop_bit:    in pins, 1 [5]      ;read 1 bit    set x, 31 [30]loop_inner:    nop [31]    jmp x--loop_inner    jmp y--loop_bit        push                        wait 0 gpio SO_PIN  ;wait signal for slave to transmit        pull    wait 0 pin 0 [4]    ;    set pindirs, 1      ;set pin out    set y, 17           ;send 18 bits including start and end bitloop_bit2:    out pins, 1 [5]      ;send 1 bit    set x, 31 [30]loop_inner2:    nop [31]    jmp x--loop_inner2    jmp y--loop_bit2    set pindirs, 0      ;set pin input    wait 1 gpio SC_PIN  ;wait end transmission    .wrap

Statistics: Posted by Jerahya — Thu Nov 07, 2024 6:21 pm — Replies 2 — Views 65



Viewing all articles
Browse latest Browse all 4501

Trending Articles