1 Attachment(s)
SERIN2 not working with 16F628
I have searched long an hard in the datasheets, forum and archive, but I am unable to get my 16F628 to receive any data from a 12F675 with SERIN2.
I have the 16F628 acting as a master, with a 12F675 being the slave unit. The 628 sends a bit of data, then does a SERIN2 WAIT. The slave receives the data and replies back with a number.
I have connected a logic analyzer, and the data is being sent from the master to slave and the slave is responding. The Logic analyzer interprets the data correctly at 2400 8N1. Yet the 628 master times out.
Things to note:
<ul>
<li>16F628 is using an external 10Mhz resonator
<li>Programmer for 16f628 is a ISP Pro 0818
<li>12F675 is using a <b>calibrated</b> internal oscillator
</ul>
I have reduced this down to small test programs. Here is the 16F628 master code:
<table border=1><tr><td>
<code>
@ Device PIC16F628,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_ON,BOD_O FF,LVP_OFF, CPD_OFF
DEFINE OSC 10
DEFINE CHAR_PACING 2400
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 2
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 1
Counter var Byte
debug "Initializing...",13,10
CMCON = %00000111
TRISA = %00000010
TRISB = %00000000
VRCON = %00000000
INTCON = %00000000
RCSTA = %00000000
TXSTA = %00000000
SPBRG = %00000000
pause 1000
loop:
pause 1000
debug "Sending to slave...",13,10
' send out some stuff
SEROUT2 porta.0, 16780, ["hello"]
' wait and read
SERIN2 porta.1, 16780, 300, TimeOut, [WAIT("SYNC"), Counter]
DEBUG "Got from slave:", DEC Counter, 13, 10
Timeout:
DEBUG "Timeout from slave", 13, 10
goto loop
</code>
</td></tr></table>
Here is the 12F675 slave code:
<table border=1><tr><td>
<code>
@ Device PIC12F675,WDT_ON,PWRT_ON,PROTECT_OFF,MCLR_ON,BOD_O FF 'sets configuration
Counter var byte
CMCON = %00000111
TRISIO = %00000000
ANSEL = %00000000
Pause 100
Counter = 0
loop:
Serin2 gpio.2, 16780, [WAIT("hello")]
PAuse 2
SEROUT2 gpio.4, 16780, ["SYNC", Counter]
Counter = Counter + 1
goto loop
</code>
</td></tr></table>
A JPG of the Logic Analyzer is attached. Your help is very much appreciated.
thanks
Don