**The thread is now CLOSED. This was confirmed as a issue/bug by Microchip. Please do not reply to this thread.
Please ensure you are using Great COW BASIC v.0.95.008 or greater to ensure you are using a release the addresses this bug.
Anobium
**
Start of original posting.....
I'm getting the follow error when compiling..Error log is:
Error: GCASM: Symbol 147C0 has not been defined ---- current converted code from Proton Basic
~~~~
'
#chip 16F18326, 32 ' Great Cow Basic
#Config RSTOSC_HFINT32,clkouten_off,fcmen_off '' ,ieso_off
#Config mclre_on,pwrte_on,wdte_off,boren_off ,stvren_off '' , PLLEN_on,
#Config wrt_off,LVP_OFF,cp_off,cpd_off
'---------------------------------------
#define USART_BAUD_RATE 115200 '9600,19200,38400,57600,78600,115200,230400
Dir PORTC.4 Out
Dir PORTC.5 in
#define USART_DELAY 5 ms '?
#define USART_BLOCKING ,
'---------------------------------------
#define HI2C_BAUD_RATE 400
#define HI2C_DATA PORTC.1
#define HI2C_CLOCK PORTC.0
Dir HI2C_DATA In
Dir HI2C_CLOCK In
'---------------------------------------
Macro Start_Cnts ()
TMR1L=0 : TMR1H=0 : TMR2=0 : T1CON.0=1 : T2CON.2=1
End Macro
Macro Stop_Cnts ()
T1CON.0=0 : T2CON.2=0 : TCTR=T1CTR
End Macro
'===============================================================================
Macro SerPutFill (Char,Length) ' SerPutFill ( "-" : Y = 80)
For V = 1 To Length
HSerPrint Char
Next V
HserPrintCRLF
Return
End Macro
Macro I2cINIT ()
SSP1CON1 = 0x28 : SSP1CON2 = 0: SSPADD = 79: SSPSTAT = 0xC0
End Macro
#define I2C_Wrt=0
#define I2C_Rd=1
'-------------------------------------------------------------------------------
Dim Inbyte As Byte
Dim Za As Byte
Dim Current_Grp As Byte
Dim Current_K As Byte
Dim Cc As Byte
Dim AdrLo As Byte
Dim AdrHi As Byte
Dim Ww As Byte
Dim Vv As Byte
Dim Work As Long
Dim BaudSel As Byte
Dim T2cnt As Byte
Dim IntCnt As Byte
Dim ExtCnt As Long
Dim Tmr1Counter As Long
Dim TemperatureCnt As Long
Dim AdjustedCnt1 As Long
Dim AdjustedCnt2 As Long
Dim AvgPulseCount As Word
Dim AvgTemperature As Word
Dim TCTR As Word
Dim ADCa As Word
Dim ADCb As Word
Dim ADCc As Word
Dim ADCd As Word
Dim FHi As Word
Dim FLo As Word
Dim Ycnt As Word
Dim Xcnt As Word
Dim Delta_Freq As Word
Dim Delta_PPM As Long
Dim PPM_Now_Temp As Long
Dim Found As Byte
Dim IntCntA As Byte
Dim Xx As Byte
Dim Yy As Byte
Dim CRC As Byte
'-----------------------
Dim BaudAsc As String * 6 ' ascii baud reference
Dim Parasite As Byte
Dim Pdata As Byte ' P-parasite + uses 5v
Dim RxCR As Byte ' 2^7=cr rcv'd 0-63 valid position of cr
Dim RxIn As Byte ' store incoming data this index 0-63
Dim RxOut As Byte ' data byte out location
Dim RxChar As Byte
Dim RxOld As Byte
Dim cidx As Byte
Dim PK As Byte ' probe K
Dim CmdW As Long
Dim RxBuf As String * 96 ' byte array with 64 bytes
Dim ESlot As Long
Dim PPMhi As Word
Dim PPMlo As Word
Dim KADR1 As Byte ' length of cmd
Dim AvgCnt As Byte ' track sample s
Dim Command As Byte
Dim KGrp As Byte
Dim KADR As Byte
Dim AdjustedPPM1 As Long
Dim AdjustedPPM2 As Long
Dim Tcount As Word
Dim KDATA As Byte
Dim Eprom_Grp As Byte ' K table address
Dim SolutionPPM As Word
Dim KTALoad As Byte
Dim KTAVal As Byte
Dim KTASlot As Byte
Dim CRCDATA As Byte
Dim Zz As Byte
Dim CMD As String * 20
Dim CMDa As String * 20
Dim CMD1 As String * 20
Dim CMD2 As String * 10
Dim CMD3 As String * 10
Dim CMDb As String * 10
Dim CMDc As String * 10
Dim CMDd As String * 10
Dim CMDe As String * 3
Dim CMDf As String * 2
Dim CMDg As String * 2
Dim CMDh As String * 6
'----------------------------------
Dim Aa As Byte
Dim Bb As Byte
Dim Dd As Byte
Dim Ls As Byte
Dim Ws As Byte
Dim Xs As Byte
Dim Ys As Byte
Dim PH As Byte ' ph10
Dim MCP As Word
Dim deviceID as Byte
'===============================
GoTo mainx
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sub INTERRUPT: If PIR1.1 = 1 Then GoTo Tmr2int End If ' not T2 interrupt 32+ ms
' Nop
RxI:
RxINT:
If PIR1.5 = 0 Then Retfie End IF ' rcif interrupt
'' HRSOut "<i" ''="" if="" (rcsta="" &="" 6)=""> 0 Then GoTo Uart_err '
Inc RxIn ' ?
If RxIn >= 96 Then RxIn = 0 End IF
RxCR = RCREG
RxSit:
RxBuf[RxIn] = RxCR ' store both 13/10
RxXit:
PIR1.5 = 0 ' clr rcif int
' Nop
'' If PIR1.1 = 1 Then GoTo Tmr2int
Retfie
Uart_err:
RCSTA.4 = 0 ' clear receiver status
' Nop
RCSTA.4 = 1 ' re-enable uart
Retfie
'------------------------------------------------
Tmr2int:
Dec T2cnt
If T2cnt = 0 Then GoTo T_Done End If
PIR1.1=0
Retfie
T_Done:
T1CON.0=0
T2CON.2=0
T2cnt=8 '' HRSOut 13,10,"TCTR-",Dec T1CTR,"-",dec tctr
TCTR=T1CTR
'-------------------------------------------------
Iexit:
PIR1.1=0 ' TMR1L=0 TMR1H=0 TMR2=0 T1CON.0=1 T2CON.2=1
Retfie ' put this code in w4int start timers/ctrs
End Sub
'===============================================================================
mainx:
main: ' 32/4=8 =>.125 </i">16 = 2us step for TMR2 1:16
'-------------------------------------------------------------------------------
'''OSCCON = %11110000 ' 8 mhz internal 8x4=32 pll
OSCTUNE = 0x2 ' 0x0 default, 0xF max freq, 0x1F min freq
'''OPTION_REG = %00000000 ' 1:2 32/4=8 8/2=4mhz => .25us/step 64
IOCAP = 0 ' RA0-1 pin change rising edge detect
IOCAN = 0 ' no detect falling edge
IOCAF = 0 ' pins that changed
TMR0LH = 0 ' 2US RESOLUTION 1:4 PRESCALE
'===============================================================================
INTCON = 0 '
PORTA = 0 '
PIE1 = 0 '
PIE2 = 0 '
ANSELA = 0x03 '%00000011 ' AN0-RA0,AN1--RA1 analog ,all digital
ANSELC = 0c0C '%00001100 ' ANSc2-Rc2, ANSc1-Rc3 analog ,
'ANSELC = 0 ' all digital bit 3,2,1,0
'''APFCON0 = 0 ' RC4=tx RC5=rx
'''APFCON1 = 0 '
BAUDCON = 0x40 ' rcv-idle brg16=0
SPBRGL = 0 '
SPBRGH = 0 '
TRISA = 0x2F '%00101111 ' Ra4 drive probe Tx / Enb 555
TRISC = 0x2F '%00101111 ' Rc4 = Tx Rc5 Rx Rc0-Scl Rc1-Sda Rc2-Ansc0 Rc3-Ansc1
'''OPTION_REG = %00000010 ' wpu enb 8.125=1 us/cnt
WPUA = 0x38 '%00111000 ' weak pullup port A
'------------------------------------------- '
TXSTA = 0 '
RCSTA = 0 '
'------------------------------------------- '
TXSTA.6 = 0 : RCSTA.6=0 ' set 8-bit=0
TXSTA.5 = 1 ' enable tx en
TXSTA.1 = 0 ' tsr 1-empty 0-full
'------------------------------------------- '
RCSTA.7 = 1 ' SPEN = 1 enb eusart '
RCSTA.4 = 1 ' CREN = 0 disenb rcv '
'-------------------------------------------------------------------------------
' sync=0, brgh=1, brgh16=1 or sync=1 brgh=0 brgh16=1
' baud = fosc / 4[spb+1 fosc/4 /[spb+1] 32/4= 8000000/baud = spb+1
' 8m/115200=69.44 => 68 8m/230400=34.7 => 34 8m/460800=17.36 => 16
' 8m/921600=8.68 => 8
'-------------------------------------------------------------------------------
wait 2000 ms 'DelayMS 2000 ' stall 2 seconds to stabilize
wait 500 ms 'DelayMS 500 ' allow baud to stabilize
HSerPrint "EC-16F1825 <baud 57600="">",13,10
GoTo Init
'===============================================================================
Init:
T1Con = 0x84 ' RA5[TKCI] extinput 00-1:1 0-stop cnt
T1GCON = 0x00 ' 1-no sync ext clk 0-ukn 1 enb TMR1
' prescale 1:64 postscale 1:16
T2CON = 0x7B ' 32/4/64/256/16= f= 30.1245cps
' 1/f = 32768 us
PIR1.1 = 0 ' TMR2IF = 0 pending T2 int
PIE1.1 = 1 ' TMR2IE =1 enable T2 int
cidx = 0 ' set cmd index = 0
RxCR = 0 ' clear RxCR received
TemperatureCnt = 0 ' Long
Tmr1Counter = 0 ' Long
AvgCnt = 1 ' byte 16 sample counter
TMR1L=0 ' count-lo
TMR1H=0 ' count-h
TMR2=0 ' time base
INTCON = 0xC0 ' enable GIE + PEIE '''''+ INTF
T1CON.0=1 ' enable T1 counting
T2CON.2 = 1 ' timer2 started
T2cnt = 8 ' count for 8 T2 periods of 32768 us
TCTR = 0
ExtCnt = 0
AvgCnt = 1
HI2CMODE Master
I2CInit ()
'-------------------------------------------------------------------------------
ClearRxBuf:
PIE1.5 = 0 ' disable usart int
PIR1.5 = 0 ' clear RCIF pending
RxIn = 0 ' clear buffer in pointer
RxOut = 0 ' clear buffer out pointer
RxCR=55
Command=0
CmdW=0
PIE1.5 = 1 ' allow uart ints
INTCON = $C0
'===============================================================================
W4INT: '' Nop ' ExtCnt = TMR1 total
PORTA.4=0 ' LED ON
wait 5 ms 'DelayMS 5 ' 5 ms
PORTA.4=1 ' LED OFF
wait 5 ms 'DelayMS 4
If RxCR= 10 Then GoSub GetRxChar
'===============================================================================
If TCTR > 0 Then
GoSub I2C
GoSub GetADC
If Cc < 0 or Cc > 0 Then ' rtn c = crc = 0 crc is good
HSerPrint " CRC ERROR = ",Cc,13,10 ''</baud>********
End If
GoTo ProcessT1
End If
W4X:
If (T2CON.2=0 And T1CON.0=0) Then
Start_Cnts
End If 'T1CON.0=0 : T2CON.2=0 : TCTR=T1CTR
GoTo W4INT
'===============================================================================
ProcessT1: '' Temperature and PulseCounts
If AvgCnt = 1 Then
ExtCnt = TCTR '' init pulse count
TemperatureCnt = Temp '' update temperature
Else
ExtCnt = ExtCnt + TCTR '' init temperature count
TemperatureCnt = TemperatureCnt + Temp '' update temperature
End If
TCTR = 0
'===============================================================================
' Obtain Temperature from 1-Wire device DS18B20
'===============================================================================
'Salinity correction approximation 5000 ppm @ 25C ==> 11000 us
'R2 = R1((T1+6.77)/(T2+6.77)) ' F 5000 ppm @ 40C ==> 8200 us
'R2 = R1((T1+21.5)/(T2+21.5)) ' C
'11000((25 + 21.5)/(40+21.5)) = 8317 us ' 5500((25 + 21.5)/(40+21.5)) = 4158 ppm
'Rx = R25 ( T25 + 21.5 )/( Tx +21.5 ) ' R25 = Rx ( Tx + 21.5) / ( T25 + 21.5 )
'===============================================================================
' Search through the groups
'===============================================================================
GetRxChar: ''If RxCR = 13 Then GoTo GetRxChar ' sty here until next char
''' If RxCR = 10 Then HRSOut "<lf> "
RxCR=129 ' make RxCR <> 0
NZ:
For Zax = 0 To 19 ' get 20 bytes max
RxOut = RxOut +1 ' buffer wrap 0-63-0
If RxOut>=96 Then RxOut=0 End IF '
CMD(Zax) = RxBuf(RxOut) ' Rxbuf chr --> cmd string
If CMD(Zax)=13 Then ' cr stop 012345678
Cc = Zax ' save cmd length
CMD(Zax)=0 ' rpl cr with 00
exit For ' found cr - so exit
End If ' crlf stripped
Next
RxIn=0 ' no stack cmds
RxOut=0
If CMD(0)=0 Or CMD(0)= 10 Then Return End IF '' was trashed
CMDa = Ucase(CMD) ' make uppercase and stripprd crlf</lf>
Return''''GoToprocess1
'-------------------------------------------
'===============================================================================
GetADC:
''trisa.0=1
''trisa.1=1
FVRCON = 0x83 ' enble FVR, 1-rdy,0-Tsen,x,,xx, 00=FVR off 01=1024 10=2048 11=4096
FVRR:
If FVRCON.6=0 Then ' wait FVR ready
GoTo FVRR
End IF
ADCON1 = 0xE3 ' RJ,fosc/64, 00=vdd 11=fvr
ANSELA = 0x03 ' enable AN0 and AN1
ANSELA = 0x03 ' AN0-RA0,AN1--RA1 analog ,all digital
ANSELC = 0x0C ' ANSc2-Rc2, ANSc1-Rc3 analog ,
'------------------- ADC0 -----------------'
ADCON0 = 0x01 ' x,00000,go/done=0,Enable=1 x,channel AN0, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv %11100011 RJ,110-Fosc/64,x,x,11-FVR
WH:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH
End IF
ADCa = ADRESL
ADCa_H = ADRESH
'------------------- ADC 1 ----------------'
ADCON0 = 0x05 ' X,00000,go/done=0,Enable=1 X,channel AN1, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv
WH1:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH1
End IF '
ADCb = ADRESL
ADCb_H = ADRESH
'------------------- ADC6 -----------------' -- RCx ADC's are reading about +80mv greater than RAx ADC's
ADCON0 = 0x19 ' x,00000,go/done=0,Enable=1 x,channel AN6, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv %11100011 RJ,110-Fosc/64,x,x,11-FVR
WH2:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH2
End IF
ADCc = ADRESL
ADCc_H = ADRESH
'------------------- ADC7 -----------------'
ADCON0 = 0x1D ' x,00000,go/done=0,Enable=1 x,channel AN7, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv %11100011 RJ,110-Fosc/64,x,x,11-FVR
WH3:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH3
End IF
ADCd = ADRESL
ADCd_H = ADRESH
Return '
'===============================================================================
'CrLf: HRSOut 13,10
' Return
'-------------------------------------------------------------------------------
CharOut:
For Vv = 1 To Yy
HSerPrint Xx 'HRSOut Xx
Next Vv
Return
'--------------------------------------------------------------------------------
D10:
Wait 10 ms
Return
'================================================================================
CRC8: '
movf CRCDATA,w ' update last crc
Xorwf CRC,f ' xor crc and new byte
Movlw 0 ' clear w reg
Btfsc CRC,0 '\
Xorlw 0x5e ' \
Btfsc CRC,1 ' \
Xorlw 0xbc ' \
Btfsc CRC,2 ' \
Xorlw 0x61 ' \
Btfsc CRC,3 ' \
Xorlw 0xc2 ' |-- build new CRC
Btfsc CRC,4 ' |
Xorlw 0x9d ' /
Btfsc CRC,5 ' /
Xorlw 0x23 ' /
Btfsc CRC,6 ' /
Xorlw 0x46 ' /
Btfsc CRC,7 ' /
Xorlw 0x8c '/
Movwf CRC ' save new crc value
Return '
'===============================================================================
I2C:
'********-----------------------------------------
' read mcp3221 voltage
' I2Addr = 0x4A << 1 | 0x00 ' x4A << 1 = x94 or 0 = x94
' I2Addr = 0x4A << 1 | 0x01 ' x4A << 1 = x94 or 1 = x95
' A0=0x48 A1=0x49 A2=0x4A A3=0x4B
' A4=0x4C A5=0x4D A6=0x4E A7=0x4F
nDev = 0
for deviceID = 0 to 255
HI2CStart
HI2CSend ( deviceID )
deviceID = deviceID or 1
If deviceID = 1 Or deviceID=2 Then
'-----------------------------------------------------------------
' HBStart
' HBusOut Xx ' 0x4a *2 +1 read from dev 0x47 x94/x95 92/93' HBusIn MCP_H' HBusAck' HBusIn MCP_L' HBStop 'Cx= MCP * .00125 ' using 5.16 ref mcp3221 input is impedance sensitive
'Ix = ADC0 * .00400 ' using 4.096 ref 'Vx = ADC1 * .00400
'Rx = (ADC6 -20) * .004 '' 80mv correction to agree with RAx' Ms = (ADC7 -20) * .004 '' 80mv correction To agree with RAx
''HRSOut "Reply = ",Hex X,"-","MCPH,MCPL = ",Hex4 MCP," - RAW - ",Dec MCP," --> ", Dec3 Cx,13,10
' HRSOut "Addr< ",Hex X,">-->","MCPH,MCPL=<",Hex4 MCP,">==>",Dec MCP," *1.25mv = "
' HRSOut Dec2 Cx," - ",Dec2 Ix," - ",Dec2 Vx," -",Dec2 Rx," - ",Dec2 Ms, 13,10
End If
Return
'--------------------------------------------------------------------------------------------
I2Ca:
HSerPrintCRLF 2
HSerPrint "Hardware I2C Discover using the "
HSerPrint CHipNameStr
HSerPrintCRLF 2
FordeviceID=0to255HI2CStartHI2CSend(deviceID)IfHI2CAckPollState=falsethenIf((deviceID&1)=0)thenHSerPrint"W"elseHSerPrint"R"EndIfHSerSend9HSerPrint"ID: 0x"HSerPrinthex(deviceID)HSerSend9HSerPrint"(d)"+str(deviceID)HSerPrintCRLFHI2CSend(0)HI2CSend(0)EndIfHI2CStopNextHSerPrintCRLFHSerPrint"End of Device Search"HSerPrintCRLF2
return
End
Last edit: Anobium 2016-07-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I 'm just trying to get the basics working now using modified demo, Serial, HI2c, and cannot get I2c to work
I think it is the PPS stuff on the 16F18326 , but can't get off the ground...
RC5=RX RC4=TX RC0=SCL RC1=SDA
I display all addresses 0-255 , have tried 2 versions , with same results. ?????????
'Set the PPS of the PWM and the RS232 ports.
Intoff
PPSLOCK = 0x55
PPSLOCK = 0xAA
PPSLOCKED = 0x00 'unlock PPS
RXPPS=0x15 'Pin RC5 source is an input for RX
RC4PPS=0x14 'Pin RC4 source is TX/CK
RXPPS=0x10 'RC0 input SCL I2c
RXPPS=0x11 'RX1 input SDA I2c
'PPSLOCK = 0x55
'PPSLOCK = 0xAA
'PPSLOCKED = 0x01 'lock PPS
'USART settings - these MUST be set after the PPS settings
#define USART_BAUD_RATE 57600
#define USART_BLOCKING
#define USART_TX_BLOCKING
#define HI2C_BAUD_RATE 100
#define HI2C_DATA PORTC.1
#define HI2C_CLOCK PORTC.0
Dir HI2C_DATA In
Dir HI2C_CLOCK In
Hi2cMode Master
; ----- Variables
' No Variables specified in this example.
; ----- Main body of program commences here.
doHSerPrint"This is a demonstration of Hardware Serial"HSerPrintCRLFwait1sfordeviceID=0to255HI2CStartHI2CSend(deviceID)ifHI2CAckPollState=falsethenif((deviceID&1)=0)thenHSerPrint"W"elseHSerPrint"R"endifHSerSend9HSerPrint"ID: 0x"HSerPrinthex(deviceID)HSerSend9HSerPrint"(d)"+str(deviceID)HSerPrintCRLFHI2CSend(0)HI2CSend(0)endifHI2CStopnextHSerPrintCRLFHSerPrint"End of Device Search"HSerPrintCRLF2loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
changed code block to and this code now discovers the mcp3221 device........
I have not locked ,, I'm not sure if it can be locked since RC0,RC1 alternate in/out????????
but then I'm just connecting pins so should be able to lock.....
now I need to get 2 bytes ?
PPSLOCK = 0x55
PPSLOCK = 0xAA
PPSLOCKED = 0x00 'unlock PPS
RXPPS=0x15 'Pin RC5 source is an input for RX
RC4PPS=0x14 'Pin RC4 source is TX/CK
RXPPS=0x10 'RC0 input SCL I2c *** not sure if needed
RXPPS=0x11 'RX1 input SDA I2c *** not sure if needed
RC0PPS=0x18 ' identify clk ******** added
RC1PPS=0x19 ' identify data ******** added
Last edit: xtal10 2016-07-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
stopped working now displays all addresses instead of x94,x95 something else must need to be done? May be a bit that needs set/reset the pwup flipping??
I can find Demos but no Xpress demos
Last edit: xtal10 2016-07-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have the Demos been tested on the 16F18326? I have pullups 1.8k installed, The 16F1825 pic works fine with this setup. This is strange it worked for about 2 hours after assigned the PPS outputs. Now its doing what it initially was doing [ie] reporting all #'s ....Just discovered the 16F1825 will work fine without resistors, Scoping the pullups I see no level changes , even when doing multiple resets,
which leads me back to the PPS stuff.......plugging on....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
xtal10:
Hopefully you didn't take my example literally as you equated the PPS correctly previously. I only mentioned the fact that the PPS module minimum requirement was RC0PPS = xx, and RC1PPS = xx, with xx being specific to your device.
Looking at the current trunk hwi2c.h it seems lacking support for newer devices that have registers now named SSPxCON1, SSPxCON2, SSPxCON3, SSPxSTAT, SSPxADD, SSPxBUF. This is the way my 16f1704 registers are configured.
I did not have any luck using I2C other that the default pin settings for the 16f1704, which were RC0 and RC1. Stick with the default pins until things are working properly.
I don't use the GCBasic inbuilt hardware I2C library. A minimal initialization (excluding the baudrate generator) would be something like this:
From a chip specific driver perspective the following are defined.
SSP1CON,533
SSP1CON1,533
SSPCON,533
SSPCON1,533
Therefore, SSP1CON is the same as SSPCON1 register, and the othter two, and, all the other registers are treated the same.
We use SSPCON1 therefore it should be OK.
The HWI2C should work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The default for this chip with respect to HW I2C should work, if you connect to the correct ports. The no pullups worries me... that would be most strange.
PPS is required for TX only. As with other chips in this range.
'Set the PPS of the RS232 port. UNLOCKPPS RC4PPS = 0x010100 'RC4->EUSART:TX;LOCKPPS
I have chips coming - so, please wait till I have this chip on a test rig here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some how I've now killed the serial,,,Will start over
I'm thinking maybe its's where I placed the Unlock/lock, The generated asm looks a little scatterd to me, but it was working for a short while, so I'm thinking I screw something up.
What is the preferred program layout...
chip
config
Unlock/lock? Dims? Define? functions? subs? Int sub? main?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The 16f1704 is very much the same as the 16f18326, 14pin with PPS, give or take an OPA module or an expanded pin select register. Like Anobium says, the default RX pin need not be defined in the PPS routine.
Here is a working example testing the transmit and receive functions with the hardware usart. It is in response to a previous forum question and for my own current setup which is being developed on the breadboard now. The PPS peripheral equates are different for the 16f18326.
The following sequence "&,64,153,208," was used as a test for the transmit send window of the GCBSynWrite inbuilt Br@y++ terminal. The CR=CR+LF and +CR boxes are not checked.
using the following, serial output was working until I added RA4 output to lock ..
I cannot toggle RA4, have tried lata.4 and porta.4 , just noticed Reset RA3 no longer works
not sure when that started...
Having FUN-FUN-FUN
'''A demonstration program for GCGB and GCB.
'''--------------------------------------------------------------------------------------------------------------------------------
'''This program ia a demonstration of Hardare Serial Communication, but, this also shows how to use PPS.
'''The RS232 transmit port is set to be on PortB.7, you can choose but in this demo you can easily change this to another port changing the PPS commands.
''':
'''@author EvanV
'''@licence GPL
'''@version 1.0a
'''@date 02.12.2015
'''**************
'Set the PPS of the PWM and the RS232 ports.
bcf Intcon.GIE ' Intoff
PPSLOCK = 0x55
PPSLOCK = 0xAA
PPSLOCKED = 0x00 'unlock PPS
'----------------------------------------------------------------------
RXPPS = 0x15 'Pin RC5 source is an input for RX
RC4PPS = 0x14 'Pin RC4 source is TX/CK
'USART settings - these MUST be set after the PPS settings
#define USART_BAUD_RATE 57600
#define USART_BLOCKING
#define USART_TX_BLOCKING
; ----- Variables
' No Variables specified in this example.
; ----- Main body of program commences here.
DIR PORTA.4 OUT
do
if PORTA.4=1 then
LATA.4=0
else
LATA.4=1
End If
HSerPrint "This is a demonstration of Hardware Serial"
HSerPrintCRLF
wait 1 s
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The port test seems to test the port as input and then sets the port as an output.
Do NOT use assembler when setting PPS with GCB
Use LOCKPPS and UNLOCKPSS
There is no need to set ANSELx. A design intent of GCB is to handle this automatically.
Use Constants rather than ports addresses to simply code.
Use indents to make your code easier to read
No need to use LATx as this is handled automatically
I am sure there could be more improvements. I am sure you do not need to set anything but the TX in PPS. I will proove this when I get my chip.
#chip 16f18326, 32#Config RSTOSC_HFINT32,clkouten_off,fcmen_off#Config mclre_on,pwrte_on,wdte_off,boren_off ,stvren_off#Config wrt_off,LVP_OFF,cp_off,cpd_off'Set the PPS of the PWM and the RS232 ports.UNLOCKPSS'----------------------------------------------------------------------RXPPS=0x15'Pin RC5 source is an input for RXRC4PPS=0x14'Pin RC4 source is TX/CKRA4PPS=0x00' Use LATA.4'----------------------------------------------------------------------RXPPS=0x10' RC0 input SCL I2cRC0PPS=0x18' SCL clock line RC0RXPPS=0x11' RC1 input SDA I2cRC1PPS=0x19' SDA data line RC1'----------------------------------------------------------------------LOCKPPS'USART settings - these MUST be set after the PPS settings#define USART_BAUD_RATE 57600#define USART_BLOCKING#define USART_TX_BLOCKING'Define constants#define SwitchIn PORTA.4#define LED PORTA.0DIRPORTA.4INDIRPORTA.0IN;-----Variables' No Variables specified in this example.;-----Mainbodyofprogramcommenceshere.doforeverifSwitchIn=1thenLED=0elseLED=1EndIfHSerPrint"This is a demonstration of Hardware Serial"HSerPrintCRLFwait1sloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
**The thread is now CLOSED. This was confirmed as a issue/bug by Microchip. Please do not reply to this thread.
Please ensure you are using Great COW BASIC v.0.95.008 or greater to ensure you are using a release the addresses this bug.
Anobium
**
Start of original posting.....
I'm getting the follow error when compiling..Error log is:
Error: GCASM: Symbol 147C0 has not been defined ---- current converted code from Proton Basic
~~~~
'
#chip 16F18326, 32 ' Great Cow Basic
#Config RSTOSC_HFINT32,clkouten_off,fcmen_off '' ,ieso_off
#Config mclre_on,pwrte_on,wdte_off,boren_off ,stvren_off '' , PLLEN_on,
#Config wrt_off,LVP_OFF,cp_off,cpd_off
'---------------------------------------
#define USART_BAUD_RATE 115200 '9600,19200,38400,57600,78600,115200,230400
Dir PORTC.4 Out
Dir PORTC.5 in
#define USART_DELAY 5 ms '?
#define USART_BLOCKING ,
'---------------------------------------
#define HI2C_BAUD_RATE 400
#define HI2C_DATA PORTC.1
#define HI2C_CLOCK PORTC.0
Dir HI2C_DATA In
Dir HI2C_CLOCK In
'---------------------------------------
Macro Start_Cnts ()
TMR1L=0 : TMR1H=0 : TMR2=0 : T1CON.0=1 : T2CON.2=1
End Macro
Macro Stop_Cnts ()
T1CON.0=0 : T2CON.2=0 : TCTR=T1CTR
End Macro
'===============================================================================
Macro SerPutFill (Char,Length) ' SerPutFill ( "-" : Y = 80)
For V = 1 To Length
HSerPrint Char
Next V
HserPrintCRLF
Return
End Macro
Macro I2cINIT ()
SSP1CON1 = 0x28 : SSP1CON2 = 0: SSPADD = 79: SSPSTAT = 0xC0
End Macro
#define I2C_Wrt=0
#define I2C_Rd=1
'-------------------------------------------------------------------------------
Dim Inbyte As Byte
Dim Za As Byte
Dim Current_Grp As Byte
Dim Current_K As Byte
Dim Cc As Byte
Dim AdrLo As Byte
Dim AdrHi As Byte
Dim Ww As Byte
Dim Vv As Byte
Dim Work As Long
Dim BaudSel As Byte
Dim T2cnt As Byte
Dim IntCnt As Byte
Dim ExtCnt As Long
Dim Tmr1Counter As Long
Dim TemperatureCnt As Long
Dim AdjustedCnt1 As Long
Dim AdjustedCnt2 As Long
Dim AvgPulseCount As Word
Dim AvgTemperature As Word
Dim TCTR As Word
Dim ADCa As Word
Dim ADCb As Word
Dim ADCc As Word
Dim ADCd As Word
Dim FHi As Word
Dim FLo As Word
Dim Ycnt As Word
Dim Xcnt As Word
Dim Delta_Freq As Word
Dim Delta_PPM As Long
Dim PPM_Now_Temp As Long
Dim Found As Byte
Dim IntCntA As Byte
Dim Xx As Byte
Dim Yy As Byte
Dim CRC As Byte
'-----------------------
Dim BaudAsc As String * 6 ' ascii baud reference
Dim Parasite As Byte
Dim Pdata As Byte ' P-parasite + uses 5v
Dim RxCR As Byte ' 2^7=cr rcv'd 0-63 valid position of cr
Dim RxIn As Byte ' store incoming data this index 0-63
Dim RxOut As Byte ' data byte out location
Dim RxChar As Byte
Dim RxOld As Byte
Dim cidx As Byte
Dim PK As Byte ' probe K
Dim CmdW As Long
Dim RxBuf As String * 96 ' byte array with 64 bytes
Dim ESlot As Long
Dim PPMhi As Word
Dim PPMlo As Word
Dim KADR1 As Byte ' length of cmd
Dim AvgCnt As Byte ' track sample s
Dim Command As Byte
Dim KGrp As Byte
Dim KADR As Byte
Dim AdjustedPPM1 As Long
Dim AdjustedPPM2 As Long
Dim Tcount As Word
Dim KDATA As Byte
Dim Eprom_Grp As Byte ' K table address
Dim SolutionPPM As Word
Dim KTALoad As Byte
Dim KTAVal As Byte
Dim KTASlot As Byte
Dim CRCDATA As Byte
Dim Zz As Byte
Dim CMD As String * 20
Dim CMDa As String * 20
Dim CMD1 As String * 20
Dim CMD2 As String * 10
Dim CMD3 As String * 10
Dim CMDb As String * 10
Dim CMDc As String * 10
Dim CMDd As String * 10
Dim CMDe As String * 3
Dim CMDf As String * 2
Dim CMDg As String * 2
Dim CMDh As String * 6
'----------------------------------
Dim Aa As Byte
Dim Bb As Byte
Dim Dd As Byte
Dim Ls As Byte
Dim Ws As Byte
Dim Xs As Byte
Dim Ys As Byte
Dim PH As Byte ' ph10
Dim MCP As Word
Dim deviceID as Byte
'===============================
GoTo mainx
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sub INTERRUPT: If PIR1.1 = 1 Then GoTo Tmr2int End If ' not T2 interrupt 32+ ms
' Nop
RxI:
RxINT:
If PIR1.5 = 0 Then Retfie End IF ' rcif interrupt
'' HRSOut "<i" ''="" if="" (rcsta="" &="" 6)=""> 0 Then GoTo Uart_err '
Inc RxIn ' ?
If RxIn >= 96 Then RxIn = 0 End IF
RxCR = RCREG
RxSit:
RxBuf[RxIn] = RxCR ' store both 13/10
RxXit:
PIR1.5 = 0 ' clr rcif int
' Nop
'' If PIR1.1 = 1 Then GoTo Tmr2int
Retfie
Uart_err:
RCSTA.4 = 0 ' clear receiver status
' Nop
RCSTA.4 = 1 ' re-enable uart
Retfie
'------------------------------------------------
Tmr2int:
Dec T2cnt
If T2cnt = 0 Then GoTo T_Done End If
PIR1.1=0
Retfie
T_Done:
T1CON.0=0
T2CON.2=0
T2cnt=8 '' HRSOut 13,10,"TCTR-",Dec T1CTR,"-",dec tctr
TCTR=T1CTR
'-------------------------------------------------
Iexit:
PIR1.1=0 ' TMR1L=0 TMR1H=0 TMR2=0 T1CON.0=1 T2CON.2=1
Retfie ' put this code in w4int start timers/ctrs
End Sub
'===============================================================================
mainx:
main: ' 32/4=8 =>.125 </i">16 = 2us step for TMR2 1:16
'-------------------------------------------------------------------------------
'''OSCCON = %11110000 ' 8 mhz internal 8x4=32 pll
OSCTUNE = 0x2 ' 0x0 default, 0xF max freq, 0x1F min freq
'''OPTION_REG = %00000000 ' 1:2 32/4=8 8/2=4mhz => .25us/step 64
IOCAP = 0 ' RA0-1 pin change rising edge detect
IOCAN = 0 ' no detect falling edge
IOCAF = 0 ' pins that changed
TMR0LH = 0 ' 2US RESOLUTION 1:4 PRESCALE
'===============================================================================
INTCON = 0 '
PORTA = 0 '
PIE1 = 0 '
PIE2 = 0 '
ANSELA = 0x03 '%00000011 ' AN0-RA0,AN1--RA1 analog ,all digital
ANSELC = 0c0C '%00001100 ' ANSc2-Rc2, ANSc1-Rc3 analog ,
'ANSELC = 0 ' all digital bit 3,2,1,0
'''APFCON0 = 0 ' RC4=tx RC5=rx
'''APFCON1 = 0 '
BAUDCON = 0x40 ' rcv-idle brg16=0
SPBRGL = 0 '
SPBRGH = 0 '
TRISA = 0x2F '%00101111 ' Ra4 drive probe Tx / Enb 555
TRISC = 0x2F '%00101111 ' Rc4 = Tx Rc5 Rx Rc0-Scl Rc1-Sda Rc2-Ansc0 Rc3-Ansc1
'''OPTION_REG = %00000010 ' wpu enb 8.125=1 us/cnt
WPUA = 0x38 '%00111000 ' weak pullup port A
'------------------------------------------- '
TXSTA = 0 '
RCSTA = 0 '
'------------------------------------------- '
TXSTA.6 = 0 : RCSTA.6=0 ' set 8-bit=0
TXSTA.5 = 1 ' enable tx en
TXSTA.1 = 0 ' tsr 1-empty 0-full
'------------------------------------------- '
RCSTA.7 = 1 ' SPEN = 1 enb eusart '
RCSTA.4 = 1 ' CREN = 0 disenb rcv '
'-------------------------------------------------------------------------------
' sync=0, brgh=1, brgh16=1 or sync=1 brgh=0 brgh16=1
' baud = fosc / 4[spb+1 fosc/4 /[spb+1] 32/4= 8000000/baud = spb+1
' 8m/115200=69.44 => 68 8m/230400=34.7 => 34 8m/460800=17.36 => 16
' 8m/921600=8.68 => 8
'-------------------------------------------------------------------------------
wait 2000 ms 'DelayMS 2000 ' stall 2 seconds to stabilize
wait 500 ms 'DelayMS 500 ' allow baud to stabilize
HSerPrint "EC-16F1825 <baud 57600="">",13,10
GoTo Init
'===============================================================================
Init:
T1Con = 0x84 ' RA5[TKCI] extinput 00-1:1 0-stop cnt
T1GCON = 0x00 ' 1-no sync ext clk 0-ukn 1 enb TMR1
' prescale 1:64 postscale 1:16
T2CON = 0x7B ' 32/4/64/256/16= f= 30.1245cps
' 1/f = 32768 us
PIR1.1 = 0 ' TMR2IF = 0 pending T2 int
PIE1.1 = 1 ' TMR2IE =1 enable T2 int
cidx = 0 ' set cmd index = 0
RxCR = 0 ' clear RxCR received
TemperatureCnt = 0 ' Long
Tmr1Counter = 0 ' Long
AvgCnt = 1 ' byte 16 sample counter
TMR1L=0 ' count-lo
TMR1H=0 ' count-h
TMR2=0 ' time base
INTCON = 0xC0 ' enable GIE + PEIE '''''+ INTF
T1CON.0=1 ' enable T1 counting
T2CON.2 = 1 ' timer2 started
T2cnt = 8 ' count for 8 T2 periods of 32768 us
TCTR = 0
ExtCnt = 0
AvgCnt = 1
HI2CMODE Master
I2CInit ()
'-------------------------------------------------------------------------------
ClearRxBuf:
PIE1.5 = 0 ' disable usart int
PIR1.5 = 0 ' clear RCIF pending
RxIn = 0 ' clear buffer in pointer
RxOut = 0 ' clear buffer out pointer
RxCR=55
Command=0
CmdW=0
PIE1.5 = 1 ' allow uart ints
INTCON = $C0
'===============================================================================
W4INT: '' Nop ' ExtCnt = TMR1 total
PORTA.4=0 ' LED ON
wait 5 ms 'DelayMS 5 ' 5 ms
PORTA.4=1 ' LED OFF
wait 5 ms 'DelayMS 4
If RxCR= 10 Then GoSub GetRxChar
'===============================================================================
If TCTR > 0 Then
GoSub I2C
GoSub GetADC
If Cc < 0 or Cc > 0 Then ' rtn c = crc = 0 crc is good
HSerPrint " CRC ERROR = ",Cc,13,10 ''</baud>********
End If
GoTo ProcessT1
End If
W4X:
If (T2CON.2=0 And T1CON.0=0) Then
Start_Cnts
End If 'T1CON.0=0 : T2CON.2=0 : TCTR=T1CTR
GoTo W4INT
'===============================================================================
ProcessT1: '' Temperature and PulseCounts
If AvgCnt = 1 Then
ExtCnt = TCTR '' init pulse count
TemperatureCnt = Temp '' update temperature
Else
ExtCnt = ExtCnt + TCTR '' init temperature count
TemperatureCnt = TemperatureCnt + Temp '' update temperature
End If
TCTR = 0
'===============================================================================
' Obtain Temperature from 1-Wire device DS18B20
'===============================================================================
'Salinity correction approximation 5000 ppm @ 25C ==> 11000 us
'R2 = R1((T1+6.77)/(T2+6.77)) ' F 5000 ppm @ 40C ==> 8200 us
'R2 = R1((T1+21.5)/(T2+21.5)) ' C
'11000((25 + 21.5)/(40+21.5)) = 8317 us ' 5500((25 + 21.5)/(40+21.5)) = 4158 ppm
'Rx = R25 ( T25 + 21.5 )/( Tx +21.5 ) ' R25 = Rx ( Tx + 21.5) / ( T25 + 21.5 )
'===============================================================================
' Search through the groups
'===============================================================================
GetRxChar: ''If RxCR = 13 Then GoTo GetRxChar ' sty here until next char
''' If RxCR = 10 Then HRSOut "<lf> "
RxCR=129 ' make RxCR <> 0
NZ:
For Zax = 0 To 19 ' get 20 bytes max
RxOut = RxOut +1 ' buffer wrap 0-63-0
If RxOut>=96 Then RxOut=0 End IF '
CMD(Zax) = RxBuf(RxOut) ' Rxbuf chr --> cmd string
If CMD(Zax)=13 Then ' cr stop 012345678
Cc = Zax ' save cmd length
CMD(Zax)=0 ' rpl cr with 00
exit For ' found cr - so exit
End If ' crlf stripped
Next
RxIn=0 ' no stack cmds
RxOut=0
If CMD(0)=0 Or CMD(0)= 10 Then Return End IF '' was trashed
CMDa = Ucase(CMD) ' make uppercase and stripprd crlf</lf>
'-------------------------------------------
'===============================================================================
GetADC:
''trisa.0=1
''trisa.1=1
FVRCON = 0x83 ' enble FVR, 1-rdy,0-Tsen,x,,xx, 00=FVR off 01=1024 10=2048 11=4096
FVRR:
If FVRCON.6=0 Then ' wait FVR ready
GoTo FVRR
End IF
ADCON1 = 0xE3 ' RJ,fosc/64, 00=vdd 11=fvr
ANSELA = 0x03 ' enable AN0 and AN1
ANSELA = 0x03 ' AN0-RA0,AN1--RA1 analog ,all digital
ANSELC = 0x0C ' ANSc2-Rc2, ANSc1-Rc3 analog ,
'------------------- ADC0 -----------------'
ADCON0 = 0x01 ' x,00000,go/done=0,Enable=1 x,channel AN0, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv %11100011 RJ,110-Fosc/64,x,x,11-FVR
WH:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH
End IF
ADCa = ADRESL
ADCa_H = ADRESH
'------------------- ADC 1 ----------------'
ADCON0 = 0x05 ' X,00000,go/done=0,Enable=1 X,channel AN1, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv
WH1:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH1
End IF '
ADCb = ADRESL
ADCb_H = ADRESH
'------------------- ADC6 -----------------' -- RCx ADC's are reading about +80mv greater than RAx ADC's
ADCON0 = 0x19 ' x,00000,go/done=0,Enable=1 x,channel AN6, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv %11100011 RJ,110-Fosc/64,x,x,11-FVR
WH2:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH2
End IF
ADCc = ADRESL
ADCc_H = ADRESH
'------------------- ADC7 -----------------'
ADCON0 = 0x1D ' x,00000,go/done=0,Enable=1 x,channel AN7, done, ADC enabled
Wait 50 us ' aquisition time
ADCON0.1 = 1 ' start conv %11100011 RJ,110-Fosc/64,x,x,11-FVR
WH3:
If ADCON0.1 = 1 Then ' wait until done
GoTo WH3
End IF
ADCd = ADRESL
ADCd_H = ADRESH
Return '
'===============================================================================
'CrLf: HRSOut 13,10
' Return
'-------------------------------------------------------------------------------
CharOut:
For Vv = 1 To Yy
HSerPrint Xx 'HRSOut Xx
Next Vv
Return
'--------------------------------------------------------------------------------
D10:
Wait 10 ms
Return
'================================================================================
CRC8: '
movf CRCDATA,w ' update last crc
Xorwf CRC,f ' xor crc and new byte
Movlw 0 ' clear w reg
Btfsc CRC,0 '\
Xorlw 0x5e ' \
Btfsc CRC,1 ' \
Xorlw 0xbc ' \
Btfsc CRC,2 ' \
Xorlw 0x61 ' \
Btfsc CRC,3 ' \
Xorlw 0xc2 ' |-- build new CRC
Btfsc CRC,4 ' |
Xorlw 0x9d ' /
Btfsc CRC,5 ' /
Xorlw 0x23 ' /
Btfsc CRC,6 ' /
Xorlw 0x46 ' /
Btfsc CRC,7 ' /
Xorlw 0x8c '/
Movwf CRC ' save new crc value
Return '
'===============================================================================
I2C:
'********-----------------------------------------
' read mcp3221 voltage
' I2Addr = 0x4A << 1 | 0x00 ' x4A << 1 = x94 or 0 = x94
' I2Addr = 0x4A << 1 | 0x01 ' x4A << 1 = x94 or 1 = x95
' A0=0x48 A1=0x49 A2=0x4A A3=0x4B
' A4=0x4C A5=0x4D A6=0x4E A7=0x4F
nDev = 0
for deviceID = 0 to 255
HI2CStart
HI2CSend ( deviceID )
deviceID = deviceID or 1
If deviceID = 1 Or deviceID=2 Then
End If
Return
'--------------------------------------------------------------------------------------------
I2Ca:
HSerPrintCRLF 2
HSerPrint "Hardware I2C Discover using the "
HSerPrint CHipNameStr
HSerPrintCRLF 2
return
End
Last edit: Anobium 2016-07-31
Error at line INTCON = $C0, this should read 0xC0
That is a most interesting program. This is not optimised for Great Cow BASIC but I am sure you will be able to get it running.
Last edit: Anobium 2016-07-19
found it line 259 Intcon = $C0 changed to Intcon = 0xC0
Looks like syntax checking could be improved ......
Now maybe I can verify what works and !works.....
Good luck.
I 'm just trying to get the basics working now using modified demo, Serial, HI2c, and cannot get I2c to work
I think it is the PPS stuff on the 16F18326 , but can't get off the ground...
RC5=RX RC4=TX RC0=SCL RC1=SDA
I display all addresses 0-255 , have tried 2 versions , with same results. ?????????
chip 16f18326, 32
Config RSTOSC_HFINT32,clkouten_off,fcmen_off
Config mclre_on,pwrte_on,wdte_off,boren_off ,stvren_off
Config wrt_off,LVP_OFF,cp_off,cpd_off
Dim deviceID as byte
Dim Reply as Byte
Dim Addr as byte
Macro I2cINIT ()
SSP1CON1 = 0x28 : SSP1CON2 = 0: SSPADD = 79: SSPSTAT = 0xC0
End Macro
; ----- Variables
' No Variables specified in this example.
; ----- Main body of program commences here.
changed code block to and this code now discovers the mcp3221 device........
I have not locked ,, I'm not sure if it can be locked since RC0,RC1 alternate in/out????????
but then I'm just connecting pins so should be able to lock.....
now I need to get 2 bytes ?
Last edit: xtal10 2016-07-19
With the 16f1704 PPS and I2C I just have this (I lock the PPS):
A couple of pointers. Look at the Xpress demos and Help file - UNLOCKPPS and LOCKPPS
stopped working now displays all addresses instead of x94,x95 something else must need to be done? May be a bit that needs set/reset the pwup flipping??
I can find Demos but no Xpress demos
Last edit: xtal10 2016-07-19
You will need valid pull ups on the i2 lines. This is not specific to Great Cow BASIC.
I know these demos work. So they are always a place to start
Have the Demos been tested on the 16F18326? I have pullups 1.8k installed, The 16F1825 pic works fine with this setup. This is strange it worked for about 2 hours after assigned the PPS outputs. Now its doing what it initially was doing [ie] reporting all #'s ....Just discovered the 16F1825 will work fine without resistors, Scoping the pullups I see no level changes , even when doing multiple resets,
which leads me back to the PPS stuff.......plugging on....
xtal10:
Hopefully you didn't take my example literally as you equated the PPS correctly previously. I only mentioned the fact that the PPS module minimum requirement was RC0PPS = xx, and RC1PPS = xx, with xx being specific to your device.
Looking at the current trunk hwi2c.h it seems lacking support for newer devices that have registers now named SSPxCON1, SSPxCON2, SSPxCON3, SSPxSTAT, SSPxADD, SSPxBUF. This is the way my 16f1704 registers are configured.
I did not have any luck using I2C other that the default pin settings for the 16f1704, which were RC0 and RC1. Stick with the default pins until things are working properly.
I don't use the GCBasic inbuilt hardware I2C library. A minimal initialization (excluding the baudrate generator) would be something like this:
@Kent. These chips are supported in the current release as they also have SSPCON1 defined.
@Xtat10. No. This specific chip was not test, however, stick with a simple demo program for a moment and we can resolve any potential driver issues.
Is this your layout?
Anyone got MCC handy? This could be the quickest way to sort the PPS out. I am on a train.
@Anobium, you mean SSP1CON1 is defined? Trunk is not current?
Edit: or do you mean it is aliased in the .dat file?
Last edit: kent_twt4 2016-07-20
From a chip specific driver perspective the following are defined.
Therefore, SSP1CON is the same as SSPCON1 register, and the othter two, and, all the other registers are treated the same.
We use SSPCON1 therefore it should be OK.
The HWI2C should work.
Trunk is up to date. I just verified.
I have just requested samples. Should be here Friday morning.
Let me test here.
OK, got it thanks!
Reading the datasheet.
The default for this chip with respect to HW I2C should work, if you connect to the correct ports. The no pullups worries me... that would be most strange.
PPS is required for TX only. As with other chips in this range.
I have chips coming - so, please wait till I have this chip on a test rig here.
Some how I've now killed the serial,,,Will start over
I'm thinking maybe its's where I placed the Unlock/lock, The generated asm looks a little scatterd to me, but it was working for a short while, so I'm thinking I screw something up.
What is the preferred program layout...
chip
config
Unlock/lock? Dims? Define? functions? subs? Int sub? main?
The 16f1704 is very much the same as the 16f18326, 14pin with PPS, give or take an OPA module or an expanded pin select register. Like Anobium says, the default RX pin need not be defined in the PPS routine.
Here is a working example testing the transmit and receive functions with the hardware usart. It is in response to a previous forum question and for my own current setup which is being developed on the breadboard now. The PPS peripheral equates are different for the 16f18326.
The following sequence "&,64,153,208," was used as a test for the transmit send window of the GCBSynWrite inbuilt Br@y++ terminal. The CR=CR+LF and +CR boxes are not checked.
using the following, serial output was working until I added RA4 output to lock ..
I cannot toggle RA4, have tried lata.4 and porta.4 , just noticed Reset RA3 no longer works
not sure when that started...
Having FUN-FUN-FUN
'''A demonstration program for GCGB and GCB.
'''--------------------------------------------------------------------------------------------------------------------------------
'''This program ia a demonstration of Hardare Serial Communication, but, this also shows how to use PPS.
'''The RS232 transmit port is set to be on PortB.7, you can choose but in this demo you can easily change this to another port changing the PPS commands.
''':
'''@author EvanV
'''@licence GPL
'''@version 1.0a
'''@date 02.12.2015
'''**************
; ----- Configuration
chip 16f18326, 32
Config RSTOSC_HFINT32,clkouten_off,fcmen_off
Config mclre_on,pwrte_on,wdte_off,boren_off ,stvren_off
Config wrt_off,LVP_OFF,cp_off,cpd_off
'----------------------------------------------------------------------
RXPPS = 0x15 'Pin RC5 source is an input for RX
RC4PPS = 0x14 'Pin RC4 source is TX/CK
'----------------------------------------------------------------------
RXPPS = 0x10 ' RC0 input SCL I2c
RC0PPS = 0x18 ' SCL clock line RC0
RXPPS = 0x11 ' RC1 input SDA I2c
RC1PPS = 0x19 ' SDA data line RC1
'----------------------------------------------------------------------
PPSLOCK = 0x55
PPSLOCK = 0xAA
PPSLOCKED = 0x01 'lock PPS
bsf Intcon.GIE ' Inton
ANSELA = b'00000011' ' 0 - digital pin
ANSELC = b'00001100' ' 1 - analog pin
TRISA = b'00101011' ' Ra5-cnt-in Ra4-LED Ra2-DQ
TRISC = b'00101111' ' Rc5-Rx RC4-Tx RC1-SDA RC0-CLK
; ----- Variables
' No Variables specified in this example.
; ----- Main body of program commences here.
DIR PORTA.4 OUT
do
if PORTA.4=1 then
LATA.4=0
else
LATA.4=1
End If
HSerPrint "This is a demonstration of Hardware Serial"
HSerPrintCRLF
wait 1 s
Code feedback. PLEASE read the Help File.
I am surprised the code ran.
I am sure there could be more improvements. I am sure you do not need to set anything but the TX in PPS. I will proove this when I get my chip.
Please use the demos please.
Edit '\Demos\Serial Communications Solutions\Hardware Serial using PPS Solutions\Hardware Serial using PPS_16f1709.gcb'.
Change the chip, revise the PPS (as shown aboove) and test.
Just get the serial working, then the i2c.