You can use a hardware interrupt to act as a hardware serial receive. Hook your TX from your device to a hardware interrupt. Set the edge detect to falling. Set that port/pin to SoftSerial RX. Set any other pin to SoftSerial TX.
This is with my new micro controller so it will probably need modying for your device, but I have used it on an older model that had hardware interrupts and it worked.
#chip 16f19176, 32#include <SoftSerial.h>'======= Simulate hardware rx ==============================#define SER1_TXPORT PORTB#define SER1_TXPIN 1#define SER1_RXPORT PORTB 'needs to be a port and pin#define SER1_RXPIN 0 'that is an interrupt#define SER1_BAUD 9600#define SerInPort1 PORTB.0#define SerOutPort1 PORTB.1'Set pin directionsdirSerOutPort1OutDirSerInPort1InsetSerOutPort1on#define SOFTWARE_BUFFER1 60dimrxbuf1asstring*SOFTWARE_BUFFER1'uses a string for a bufferdimrxflag1asInteger'flag to tell when new charrxflag1=0rxbuf1(0)=0INTEDG=0'Interrupt on falling edgeOnInterruptExtInt0CallRx1Int'===================================doifrxflag1=1Then' new character in bufferrxflag1=0' reset buffer flag'----- start char is ? and end char is CR -----------if(rxbuf1(1)="?")and(rxbuf1(rxbuf1(0))=13)Then'complete messagerxbuf1(1)="!"'change start charwait500us'need brief delay before send Ser1Printrxbuf1rxbuf1(0)=0'clear bufferendifendifloopsubRx1Intrxbuf1(0)++'inc char locationrxbuf1(rxbuf1(0))=Ser1Receive'store char in string variableifrxbuf1(0)=SOFTWARE_BUFFER1then'if end of bufferrxbuf1(0)=0' start overendifrxflag1=1'set flag for new characterendsub
Later,
Clint
Last edit: Clint Koehn 2018-07-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Simple, Elegant and addresses the main downfall of SoftSerial.
I, and I am sure many others, will find this both useful and inspirational.
Thanks for sharing.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the kind words Chris. I have a chip that has 2 hardware serial ports but I needed a third one. One radio went to the computer, one was for a sensor board I made and I needed a third one for a 4D display.
Later,
Clint
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can use a hardware interrupt to act as a hardware serial receive. Hook your TX from your device to a hardware interrupt. Set the edge detect to falling. Set that port/pin to SoftSerial RX. Set any other pin to SoftSerial TX.
This is with my new micro controller so it will probably need modying for your device, but I have used it on an older model that had hardware interrupts and it worked.
Later,
Clint
Last edit: Clint Koehn 2018-07-27
Simple, Elegant and addresses the main downfall of SoftSerial.
I, and I am sure many others, will find this both useful and inspirational.
Thanks for sharing.
Cheers
Chris
Thanks for the kind words Chris. I have a chip that has 2 hardware serial ports but I needed a third one. One radio went to the computer, one was for a sensor board I made and I needed a third one for a 4D display.
Later,
Clint