Syncronus serial port

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
Posts: 263
Joined: Tue Oct 03, 2006 8:54 pm

Syncronus serial port

Post by richardb » 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

Code: Select all

Public Sub Setclk(pSPBRG As Word )
   SPBRG_Reg = pSPBRG.byte0
   #if USART2_BRG16
   SPBRGH_Reg = pSPBRG.byte1

   #if USART2_BRG16
   BRG16 = 1
End Sub

Sub SyncronusSetup ()
     Setclk(11) '11 is 1us clock

	SYNC=1 '1 enables syncronus
	TX9=0' this is for 8(0) or 9 bits(1)
	TRISB.4  =1'0
	TRISB.5 =1'0   

End Sub

Sub init_pps()
    // unlock pps registers for change (disables interrupts)
    pps.assign_input(PPS_RX2, PPS_IN_RP7) '7  
    pps.assign_input(PPS_CK2, PPS_IN_RP8)
    // relock pps config (restores interrupt enable)
End Sub 

'+++++++++++++++++++program run once++++++++++++++++++++++++++++++++++++++++++++++++	
TRISA = %11111111
TRISB = %00111111
TRISC = %11111011
TRISD = %11111111
TRISE = %11111111
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%
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

'***********************MAIN PROGRAM LOOP****************************
While true
        If Overrun Then 
		If USART2.DataAvailable = true Then

		led=Not led

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


Jerry Messina
Swordfish Developer
Posts: 1203
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Syncronus serial port

Post by Jerry Messina » Tue Aug 04, 2020 12:53 pm

I've only ever used the synchronous mode to transmit, so I probably can't be much help.

To receive I think you have to set either SREN or CREN, and clear them when you want to transmit.
There's a better description of using sync mode in other datasheets like the 26K22.

If you're the master and you don't need a continuous clock output it would probably be easier to just bit-bang sync mode.
That way you don't have to mess with pps and you can use whatever pins you like.
The shift.bas module would probably work (or something similar to it).

Posts: 263
Joined: Tue Oct 03, 2006 8:54 pm

Re: Syncronus serial port

Post by richardb » Tue Aug 04, 2020 1:09 pm

Thanks Jerry, I have the master end working fine, i just cant get the slave to receive, and i bet in the end it will be a silly thing that i haven't done.

Post Reply