Is it possible to make unidirectional serial port via 1 pin with PBP?


+ Reply to Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    504

    Default Is it possible to make unidirectional serial port via 1 pin with PBP?

    Hello. My OG-4 ugprade to nixie clock is almost finished. Now I want to connect it to main chip to receive mode selection statements. I have only 1 pin available on main chip, so will single directional serial connection work with PBP in such config? I want only to be able to transmit the commands, without receiving anything back. The main chip is 16F887 and 2nd - 12F683. Will SERIN/SEROUT statements work?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,239

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    In theory, yes.
    In practice though it depends on what else the two chips are doing because if the sender just "speaks" randomly it's likely that the receiver will miss the message if it's doing any other work in meantime.

    You'd need implement some sort of handshake scheme where the two chips first "syncs up" before the actual serial data.

  3. #3
    Join Date
    Feb 2013
    Posts
    504

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    Sender can "repeat" his "message" until user says him to stop -The idea is to allow users have various kinds of animation of OG-4 dekathron, which he selects from the setup menu. The receiver will be doing the code from OG-4 topic.

  4. #4

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    There is nothing in the protocol that prevents one way only communications.
    I have done this many times and never had an issue.
    The receiver will need an interrupt routine to make sure nothing is missed.

  5. #5
    Join Date
    Feb 2013
    Posts
    504

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    Great. Thanks. The receiver will enter "config mode" upon power up, so user can adjust whatever he needs to be changed, after exiting it, it will operate independently.

  6. #6
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    313

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    Just for ideas, I believe the DH11 (or whatever it is) temperature & humidity sensor uses 1-wire communication. You might also look at CAN, and I2C for ideas. You would need an Open Drain pin (when in output mode), or configure a transistor/MOSFET/diode to create an OD condition from both ends.

    The basic idea is a pull-up resistor creates an "Idle High" situation. Pulling the line Low is how either side initiates communication. Using INT0 (INT1_2) or IOC you could know when to look for a transmission (ISR). Unless transmitting, the pin would be configured as an Input (TRISx.x = 1), so it is able to look for packets from the other chip. With CAN, if the Sender is attempting to send a High signal, but the line is Low, Arbitration states the other chip is also trying to communicate and the looser (the one unsuccessfully trying to send a High signal) backs out. To transmit, you would first clear the TRISx.x bit, then begin sending. When finished, set the TRISx.x bit so you can then receive on the same pin.

    You would probably have to create your own protocol, but look at how exciting a challenge that might be!

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,179

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    For one pin bi-directional communication, without hardware serial port but with Serin and Serout soft commands; here is something to work on. Just a demo.
    I chose 628A for demo because of its popularity around;
    It can be any PIC (almost any).

    The circuit is for demo purposes only to show how the concept works.
    In real application, since this is a communication, a precision external crystal needs to be used and config fuse has to be changed.

    In this example, internal weak pull ups are used for buttons; and for comm pin idle state.
    If the PIC you use has no internal weak pull ups, then have 22K...100K resisitor connected to Vdd from these pins.


    Idea is to use RB0 int pin to detect incoming data pulse; sender (transmitter) first sends two zeros at the beginning of the package; Receiver side jumps into int routine and starts waiting for "ABX" header.
    Play as you wish.


    Code:
    #CONFIG
        __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_OFF & _BODEN_ON & _LVP_OFF & _CP_ON
    #ENDCONFIG
    
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 5
    
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 6
    
    
    CMCON = 7
    VRCON = 0
    TRISA = 0
    TRISB = 0
    
    PORTA = 0
    PORTB = 0
    
    ComPin var PORTB.0
    Btn1  var PORTB.3
    Btn2  var PORTB.4
    ActLED VAR PORTB.7
    TxByte var byte
    RxByte var byte
    RxCount var byte
    TOutFlag var bit
    
    ' ===== Interrupt routine ============
    ' Include files for DT's interupt routines.
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ; Include if using PBP interrupts
    
    ASM
    INT_LIST  macro                ; IntSource,   Label,  Type, ResetFlag?
            INT_Handler INT_INT, _INTX, PBP, yes
        endm
        INT_CREATE                ; Creates the interrupt processor
    ENDASM
    
    
    
    Setup:
        input btn1
        input btn2
        input compin
        OPTION_REG.7 = 0    ' pull ups enabled.
        OPTION_REG.6 = 0    ' int on falling edge of RB0.
        
        RxCount = 0
     
        lcdout $fe,1,"Hello Mars"
        Pause 500
        lcdout $fe,1
    
    @   INT_ENABLE INT_INT      ; enable int on RB0.
        
    Begin:
        rxbyte = 0
        toutflag = 0
        
        repeat
            lcdout $fe,1,"Idle ?"
            pause 10
        until compin = 1   ' internal pull up is used for idle state.
        
        ActLED = 0
    
        pause 10
        lcdout $fe,1,"Waiting for Data"    
        
        
    Start:
        
        if btn1 = 0 then TX         ' somebody pressed the button.   
        if btn2 = 0 then TX         ' somebody pressed the button.   
        if toutflag then timeout2    ' Last receive attempt was not succesful.
        
        pause 1
        
        goto start
    
    
    
    
    
    TX:
    
        ActLED = 1
        
        txbyte = 0
        if btn1 = 0 then txbyte = 1
        if btn2 = 0 then txbyte = 2
        
        SerOut2 compin,396, [0,0,"ABX",txbyte]  ' 0,0 is to create an interrupt on the other side.   ' 2400 driven true.
        input compin  ' leave the line in idle state always after each transmit.
    
    BtnBounce:      ' button de-bounce.
        pause 10
        if btn1 = 0 then BtnBounce
        if btn2 = 0 then BtnBounce
        
        goto begin
    
    
    
    TimeOut2:
        lcdout $fe,1,"Time Out"    
        pause 250    
        
        goto begin
        
        
    INTX:
        ActLED = 1
        TOutFlag = 1      ' if this flag gets cleared later, then we have a succesfull receive.
        SerIn2 compin,396,1000,Timeout1,[wAIT("ABX"),rxbyte]     '2400 driven true.
        TOutFlag = 0      ' clear the flag; 
        lcdout $fe,$c0,"Rx:",dec3 rxbyte, " Cnt:", dec3 rxcount  
        
        ActLED = 0
    
        rxcount = rxcount + 1
        
    
    Timeout1:
    
    
    @ INT_RETURN         
    
    
    end
    Name:  onepincomm.jpg
Views: 104
Size:  104.7 KB
    Last edited by sayzer; - 5th May 2020 at 22:56.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Feb 2013
    Posts
    504

    Default Re: Is it possible to make unidirectional serial port via 1 pin with PBP?

    If I had extra pins for external crystal, I'd find another ways for communication.

    As I think, FSK (Frequency shift keying) appears to be simplest and most efficient way.

Similar Threads

  1. Serial port data pin
    By Michael in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 18th July 2009, 15:13
  2. Why (or how to) make a port array for OW
    By Roy___ in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd February 2009, 23:30
  3. make a low voltage output from a PIC pin
    By emptyset in forum General
    Replies: 1
    Last Post: - 8th February 2008, 19:20
  4. converting USB to SERIAL port (9 pin)
    By PoTeToJB in forum USB
    Replies: 1
    Last Post: - 29th March 2006, 21:10
  5. Port pin problems
    By sgreelish in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th March 2004, 18:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts