Syncronus serial port
Posted: Tue Aug 04, 2020 10:16 am
I dont know if anyone can help but I've beed trying to use the syncronus serial part of the usart on a pic 18f47j53 and i'm struggling. I've never used this mode before and i think whats complicating matters is that I'm trying to use boards that i already have and that means using the pps module wich i'm not too confident with.
I've managed to get the sync transmit to work (work meaning i can see the sync and data pins toggle. but i cant read anything using the following code
sorry if its a bit hacked around but i have been trying various things and I'm starting to lose the will....
I have tried googling for examples but i was finding it difficult as either no one uses it or whenever asynchronous appears so does synchronous so it skews the search
Richard
I've managed to get the sync transmit to work (work meaning i can see the sync and data pins toggle. but i cant read anything using the following code
Code: Select all
Public Sub Setclk(pSPBRG As Word )
SPBRG_Reg = pSPBRG.byte0
#if USART2_BRG16
SPBRGH_Reg = pSPBRG.byte1
#endif
#if USART2_BRG16
BRG16 = 1
#endif
End Sub
Sub SyncronusSetup ()
Setclk(11) '11 is 1us clock
SYNC=1 '1 enables syncronus
SPEN=1
CSRC=0
CREN=1
'sren=0
TX9=0' this is for 8(0) or 9 bits(1)
TXEN=0
TRISB.4 =1'0
TRISB.5 =1'0
End Sub
Sub init_pps()
// unlock pps registers for change (disables interrupts)
pps.unlock()
pps.assign_input(PPS_RX2, PPS_IN_RP7) '7
pps.assign_input(PPS_CK2, PPS_IN_RP8)
// relock pps config (restores interrupt enable)
pps.lock()
End Sub
'+++++++++++++++++++program run once++++++++++++++++++++++++++++++++++++++++++++++++
TRISA = %11111111
TRISB = %00111111
TRISC = %11111011
TRISD = %11111111
TRISE = %11111111
SetAllDigital
CM2CON = %00000100 'disable comparater config
ADCON1 = %11000000 'adc config
ANCON0 = %11111111 'adc config
ANCON1 = %00011111' turns portsan8-12 to digital and turns on the voltage ref'although not used in this case
ODCON1 = %00000000 //set open drain to disable
ODCON2 = %00000000 //set open drain to disable
ODCON3 = %00000000 //set open drain to disable
CCPTMRS1 = %00000000 'got j53
CCPTMRS2 = %00000000 'got j53
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 12 ' 230400 Baud @ 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
init_pps()
'***********************MAIN PROGRAM LOOP****************************
USART.Write("Start",13)
While true
If Overrun Then
USART.Write("O")
ClearOverrun
EndIf
If USART2.DataAvailable = true Then
USART.Write(USART2.ReadByte)
EndIf
led=Not led
Wend
I have tried googling for examples but i was finding it difficult as either no one uses it or whenever asynchronous appears so does synchronous so it skews the search
Richard