-
Serin Not Recognizing Qualifier From Another PIC
Hi Experts,
I have a very simple task to perform. I need to pass a couple of bytes from one PIC12F683 to another PIC12F683 and can't get it to work! I've tried everything that I could think of and can't pinpoint the problem. I am using GPIO.5. I have been very successful with SERIN in other projects. In fact, I am receiving packets from a radio receiver using GPIO.0 on this same PIC and it works fine. For some reason GPIO.5 is not cooperating.
The Weak Pullup on GPIO.5 (DataOut) pin is enabled and the data is transmitted and received True". My idle state is in the "Mark" condition (High).
The TX PIC sends this -
Serout DataOut,1,[ProgID,IDByte] ' Xmit Qualifier and new ID
The TX PIC is sending the packet out. I have my oscilloscope connected to verify it. I don't think the Qualifier is being recognized or processed. What am I missing???
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''
Receiver Code -
#CONFIG
; set CONFIG1 for internal oscillator, watchdog on, MCLR pin as OFF
__config _WDTE_ON & _MCLRE_OFF & _INTOSCIO & _PWRTE_ON
#ENDCONFIG
OSCCON = 100000 ' Set system clock 4MHz(1MHz internal w/x4 PLL enabled)
DEFINE OSC 4 ' Calibrate PBP timing to 4MHz system clock
OPTION_REG = 000000 ' Enable Weak Pullups Control
WPU = 100000 ' Disable all Weak Pullups except GPIO.5
ANSEL = 0000 ' No analog inputs
TRISIO = 1001 ' Make GP1, GP2 outputs. GP0, GP3, GP4 & GP5 = inputs
CMCON0 = 0111 ' Turn off comparators
ADCON0 = 0 ' Turn off A/D
IDByte var byte ' Receiver ID.
AlarmByte var Byte ' Received Alarm
AlarmVal var byte ' Alarm Zone(s)
RxIn var GPIO.0 ' Incoming Packet Port
Z1Alarm var GPIO.2 ' Zone1 Alarm LED
Z2Alarm var GPIO.1 ' Zone2 Alarm LED
ByteSum var Byte ' IDByte & AlarmByte Sum Value
ChkSum var byte ' ChkSum value to test
ProgID var byte ' Programmer Present Verify
PrgIn var GPIO.5 ' Programmer Detect & Data Port
IDByteRx var byte ' New IDByte
ProgIDRx var byte ' Received Programmer ID
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
MainLoop:
Serin PrgIn,1,5000,PassProg,[ProgIDRx],IDByteRx ' Wait for 5 seconds for new I.D. to arrive
if ProgIDRx = $A THEN GOSUB UpdateID ' Verify arrival and execute UpdateID Subroutine
PassProg: ' No Packet received - Timeout reached - Jump out and repeat
PAUSE 500
GOTO MainLoop
UpdateID:
Z1Alarm = 1 : Z2Alarm = 1 ' LEDs to Confirm programing Subroutine
PAUSE 500
Z1Alarm = 0 : Z2Alarm = 0 ' Turn off LEDs
PAUSE 1000
Z1Alarm = 1 : Z2Alarm = 1 ' LEDs to Confirm in programing mode
PAUSE 1000
Z1Alarm = 0 : Z2Alarm = 0 ' Turn off LEDs
IDByte = IDByteRx
Write 1, IDByte ' Write new ID to EEPROM
RETURN
END
I appreciate your help. Thank you!
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi,
I have not looked closely at your code yet and I don't know if this will make any difference but I did react to the following:
Quote:
The Weak Pullup on GPIO.5 (DataOut) pin is enabled and the data is transmitted and received True".
Please note that the WPU is turned off when pin is configures as an output. See section 4.2.2 in the datasheet.
Apart from that, are both PICs on the same PCB, sharing the same power supply and, more importantly, the same ground?
-
Re: Serin Not Recognizing Qualifier From Another PIC
Thank you Henrik for you prompt reply.
The Receiver PIC's GPIO.5 is indeed configured as an input and the two systems do share a common ground.
Transmit PIC - GPIO.2 is set as an output and the outbound packet is sent by SEROUT DataOut,1,[ProgID,IDByte]
Receive PIC - GPIO.5 is set as an input and is configured to receive the packet by SERIN PrgIn,1,5000,PassProg,[ProgIDRx],IDByteRx
I didn't include the transmitter PIC code because the oscilloscope verified that the packet is being sent.
I wonder... what logic state should SERIN be idling at? I have it at logic high to generate a "mark" condition.
-
Re: Serin Not Recognizing Qualifier From Another PIC
two thoughts looking at your code.........
...ProgIDRx = $A............ did you CLEAR ProgIDRx after reception and might need to be ....$"A" not sure but
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Amgen,
Thanks for the reply. Yes, ProgIDRx is cleared. And its value is $A (or10). But, I haven't been able to receive it yet because nothing is being received. SERIN always exits upon the 5 second Timeout variable "PassProg" as if nothing is present at the pin.
And, in addition, If I had noise on the pin, SERIN would never time out. So, that indicates that SERIN is, at least, partially working, I would think.
-
Re: Serin Not Recognizing Qualifier From Another PIC
I don't really use serin so I can't be of much help, but just to educate me: isn't the contents inside the square brackets a qualifier or filter - like the WAIT modifier in serin2?
Troy
-
Re: Serin Not Recognizing Qualifier From Another PIC
one easy thing to do to troubleshoot your system....... add a temporary serout for the receiving 283 to see receptions and get all that working first as you continue with the rest of your code.... (I know you know all this) but it is like proofing the functions as you go along
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Troy,
Yes, the bracketed variable is the qualifier. SERIN won't receive or pass the data until it recognizes the presence of the qualifier in the received packet. For some reason, my qualifier is not being recognized or, GPIO.5 isn't correctly configured for SERIN? Or, something else???
-
Re: Serin Not Recognizing Qualifier From Another PIC
Thanks Amgen. Good advice!
-
Re: Serin Not Recognizing Qualifier From Another PIC
Still no progress. Beating my head against my desk on this one!
-
1 Attachment(s)
Re: Serin Not Recognizing Qualifier From Another PIC
if using 12f683 ..... check your OSCCON ..... no PLL on 12f683 unless there is new 12f....
Attachment 9659
-
Re: Serin Not Recognizing Qualifier From Another PIC
Quote:
Originally Posted by
JESmitter
Hi Troy,
Yes, the bracketed variable is the qualifier. SERIN won't receive or pass the data until it recognizes the presence of the qualifier in the received packet. For some reason, my qualifier is not being recognized or, GPIO.5 isn't correctly configured for SERIN? Or, something else???
Then, don't you need to nominate the qualifier as being something? like:
Serin PrgIn,1,5000,PassProg,["ABC"],IDByteRx ' Wait for 5 seconds for "ABC" to arrive then put contents in IDByteRx?
Troy
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Troy,
Here's my OSCON
OSCCON = %01100000 ' Set system clock 4MHz(1MHz internal w/x4 PLL enabled)
My SERIN SYNTAX
SERIN PrgIn,1,5000,PassProg,[ProgIDRx],IDByteRx ' Check for new I.D.
My Qualifier Variable
ProgIDRx VAR BYTE ' Received Programmer ID
My Byte of interest
IDByteRx VAR BYTE ' New IDByte
This should work, right???
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Amgen,
I don't recall why I included a PPL in my oscillator comment but, I believe that I have my OSCON statement correct for an internal 4 MHz cock. Right?
OSCCON = %01100000 ' Set system internal clock 4MHz.
Thank you for pointing that out!
-
Re: Serin Not Recognizing Qualifier From Another PIC
looks right now, ...... first post was unsure for OSCCON..... no wait !!!!! check for ... $01100001, bit 0, system clock ,,, but looks like you had it right UNLESS the configuration setting didn't set properly, so can use this one which calls for system to use int osc...... good fkin luck if all that fails:eek:
-
1 Attachment(s)
Re: Serin Not Recognizing Qualifier From Another PIC
This is a photo of the packet (8N1) generated by my PIC transmitter and that for some reason is not being received by my PIC receiver port GPIO.5. It's a two byte transmission $A and $61. Its in "true" format with idling level at +5VDC (Mark condition).
SERIN is not recognizing it... Why?
-
Re: Serin Not Recognizing Qualifier From Another PIC
Quote:
Originally Posted by
JESmitter
Hi Troy,
Here's my OSCON
OSCCON = %01100000 ' Set system clock 4MHz(1MHz internal w/x4 PLL enabled)
My SERIN SYNTAX
SERIN PrgIn,1,5000,PassProg,[ProgIDRx],IDByteRx ' Check for new I.D.
My Qualifier Variable
ProgIDRx VAR BYTE ' Received Programmer ID
My Byte of interest
IDByteRx VAR BYTE ' New IDByte
This should work, right???
Well, that's what I'm confused about. Don't you need to actually nominate something as the qualifier rather than an empty variable?
p207 of the manual:
"list of data items to be received may be preceded by one or more qualifiers enclosed within brackets. SERIN must receive these bytes in exact order before receiving the data items. If any byte received does not match the next byte in the qualifier sequence, the qualification process starts over (i.e. the next received byte is compared to the first item in the qualifier list). A Qualifier can be a constant, variable or a string constant. Each character of a string is treated as an individual qualifier."
So, if you have an empty variable as a qualifier, I guess serin is waiting for a "null" to arrive before accepting anything into IDByteRx.
That's the way I read it, but again, I've never really used serin.
Troy
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Troy,
I understand what you're saying. But I do declare ProdIDRx as a Byte variable in the beginning of the program as "ProgIDRx VAR BYTE".
What am I missing here?
-
Re: Serin Not Recognizing Qualifier From Another PIC
Quote:
Originally Posted by
JESmitter
Hi Troy,
I understand what you're saying. But I do declare ProdIDRx as a Byte variable in the beginning of the program as "ProgIDRx VAR BYTE".
What am I missing here?
Yes, I'm aware you declare it, but you don't assign anything to it. It's there as a newly declared variable with the contents of null. So, I'm guessing serin is waiting for a null character to arrive in your serial stream before accepting anything into your receiving placeholder. That's my interpretation of what I'm reading anyway.
Troy
-
Re: Serin Not Recognizing Qualifier From Another PIC
works perfectly for me if you don't try to use qualifier before you actually set it to a meaningful value as rocket troy indicated
Code:
#CONFIG; set CONFIG1 for internal oscillator, watchdog on, MCLR pin as OFF
__config _WDTE_ON & _MCLRE_OFF & _INTOSCIO & _PWRTE_ON
#ENDCONFIG
OSCCON = % 01100000 ' Set system clock 4MHz
DEFINE OSC 4 ' PBP timing to 4MHz system clock
OPTION_REG.7 = 0 ' Enable Weak Pullups Control
WPU = % 00100000 ' Disable all Weak Pullups except GPIO.5
ANSEL = 0 ' No analog inputs
TRISIO = % 00111001 ' Make GP1, GP2 outputs. GP0, GP3, GP4 & GP5 = inputs
CMCON0 = % 00000111 ' Turn off comparators
IDByte var byte ' Receiver ID.
IDByteRx var byte ' New IDByte
Z1Alarm var GPIO.2 ' Zone1 Alarm LED
Z2Alarm var GPIO.1 ' Zone2 Alarm LED
ProgIDRx var byte ' Received Programmer ID
PrgIn var GPIO.5 ' Programmer Detect & Data Port
ProgIDRx = $d ' define qualifier
gpio=0
'''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''
MainLoop:
Serin PrgIn,1,[ProgIDRx],IDByteRx ' Wait for new I.D. to arrive
GOSUB UpdateID ' Verify arrival and execute UpdateID Subroutine
GOTO MainLoop
UpdateID:
Z1Alarm = 1 : Z2Alarm = 1 ' LEDs to Confirm programing Subroutine
PAUSE 500
Z1Alarm = 0 : Z2Alarm = 0 ' Turn off LEDs
PAUSE 1000
Z1Alarm = 1 : Z2Alarm = 1 ' LEDs to Confirm in programing mode
PAUSE 1000
Z1Alarm = 0 : Z2Alarm = 0 ' Turn off LEDs
IDByte = IDByteRx
'Write 1, IDByte ' Write new ID to EEPROM
RETURN
ENd
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Richard,
Thank you and appreciate for your input.
The function of this program is to allow the reprogramming of the Receiver's ID.
The program is structured to provide a five second period of time upon power up of the Receiver to allow the attachment of a PIC based programmer (My design) to reprogram the ID of the respective receiver before the programs "MainLoop" begins.
I added your modifications and still couldn't get it to work. BTW, why the GPIO=0? Does that clear all GPIO ports, I presume?
Below is the modified code.
************************************************** *****************
********************** Receiver Code *********************************
************************************************** *****************
#CONFIG
__config _WDTE_ON & _MCLRE_OFF & _INTOSCIO & _PWRTE_ON
#ENDCONFIG
OSCCON = %01100000 ' Set system internal clock 4MHz
DEFINE OSC 4 ' Calibrate PBP timing to 4MHz system clock
OPTION_REG =% 00000000 ' Enable Weak Pullups Control
WPU =% 00100000 ' Disable all Weak Pullups except on GPio.5
ANSEL = %000000 ' No analog inputs
TRISIO = %111001 ' Make GP1, GP2 outputs. GP0, GP3, GP4 & GP5 = inputs
CMCON0 =%000111 ' Turn off comparators
ADCON0 = 0 ' Turn off A/D
AlarmByte var Byte ' Received Alarm
AlarmVal var byte ' Alarm Zone(s)
RxIn var GPIO.0 ' Incoming Packet Port
Z1Alarm var GPIO.2 ' Zone1 Alarm LED
Z2Alarm var GPIO.1 ' Zone2 Alarm LED
ByteSum var Byte ' IDByte & AlarmByte Sum Value
ChkSum var byte ' ChkSum value to test
ProgID var byte ' Programmer Present Verify
PrgIn var GPIO.5 ' Programmer Detect & Data Port
IDByte var byte ' Receiver ID.
IDByteRx var byte ' New IDByte
ProgIDRx var byte ' Received Programmer ID
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''
Pause 500 ' Pause for Register initialization
ProgIDRx = $D ' Define qualifier
GPIO=0
Z2Alarm = 1 'Confirm in programing mode
Serin PrgIn,1,5000,MainLoop,[ProgIDRx],IDByteRx ' Check for new I.D.
if ProgIDRx = $A then ' Match Programmer ID
IDByte = IDByteRx
Write 1, IDByte
Z1Alarm = 1 : Z2Alarm = 1 ' Confirm programing Subroutine
pause 500
Z1Alarm = 0 : Z2Alarm = 0
pause 1000
Z1Alarm = 1 : Z2Alarm = 1 'Confirm in programing mode
pause 1000
Z1Alarm = 0 : Z2Alarm = 0
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; START ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MainLoop:
I suspect that I may have a protocol issue in that my packet isn't in proper form for SERIN? Below is a JPG of my oscilloscope screen showing the packet received from the Programmer (Transmitter).
Thank you for your help!
-
Re: Serin Not Recognizing Qualifier From Another PIC
you misunderstand how the qualifier works
this can not work as you set the qualifier to 0x0d as per my example , ProgIDRx will always be 0x0d
untill you change it , serin will never change it
if ProgIDRx = $A then ' Match Programmer ID ;;// will always fail
this time out loop is pointless in this example as serin with [a qualifier ] will always block until the input qualifier is received
Serin PrgIn,1,5000,MainLoop,[ProgIDRx],IDByteRx ' Check for new I.D.
this will do the same thing
MainLoop:
Serin PrgIn,1,[ProgIDRx],IDByteRx ' Check for new I.D.
IDByte = IDByteRx
Write 1, IDByte
Z1Alarm = 1 : Z2Alarm = 1 ' Confirm programing Subroutine
pause 500
Z1Alarm = 0 : Z2Alarm = 0
pause 1000
Z1Alarm = 1 : Z2Alarm = 1 'Confirm in programing mode
pause 1000
Z1Alarm = 0 : Z2Alarm = 0
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; START ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
goto MainLoop
Quote:
I added your modifications and still couldn't get it to work.
note i used 0x0d AS a qualifier as its easer to use than 0x0a in proteus simulator
u need to either change it back to 0x0a or alter the tx code to match
Quote:
BTW, why the GPIO=0? Does that clear all GPIO ports, I presume
yes because at power up the alarm leds could be in any random state if you don't
-
Re: Serin Not Recognizing Qualifier From Another PIC
Maybe all you want then is just:
Serin PrgIn,1,5000,MainLoop, ProgIDRx
?
Troy
-
Re: Serin Not Recognizing Qualifier From Another PIC
Hi Troy,
You were right on in assuming that I misunderstood how the Qualifier works. With your help, now I do!
I've modified the program accordingly and now it works perfectly!
Thank you for taking your valuable time to assist me!
Thanks to all who responded to my post. This is a great website and support forum!