• AVR Freaks

Hot!MSSP Configuration, no waveforms present

Author
baseball07
Starting Member
  • Total Posts : 54
  • Reward points : 0
  • Joined: 2010/09/17 17:19:23
  • Location: 0
  • Status: offline
2020/05/31 14:33:50 (permalink)
0

MSSP Configuration, no waveforms present

Hi I am trying to initialize the MSSP2 module (18446) and I am not seeing any data transfer over the SDA2/SCL2 (master config).  Can someone please check my initialization and write routine to see if there is anything configured incorrectly?  My fosc = 4M, pull ups on SDA/SCL, RB5 = SCL, RB7 = SDA.
 
The below routines are used just to check to see if any data is coming over the line, which it isn't.  I will then optimize based on my application once I see I2C waveforms in any fashion on my scope.  
 
PPS config
 

 
 
 
 
 
 
 
initialization 
;***************************** Clock Selection *********************************;
banksel OSCCON1
movlw b'01100000' ;HF Int_osc Div1
movwf OSCCON1 
banksel OSCCON2
movlw b'01110000'
movwf OSCCON2
banksel OSCSTAT
bsf OSCSTAT, 6
banksel OSCEN 
bsf OSCEN, 6
movlw b'00000010' ;only used with htintosc New HFINTOSC CLK select, 32M 110, 16M 101, 8M 011, 4M 010
movwf OSCFRQ
banksel CLKRCON
movlw b'10010000' ;Reference clock for DSM, enabled, 50% duty
movwf CLKRCON
;******************************* PPS Config ***********************************;
 
 
 
 
 
 
 
banksel INTCON
bcf INTCON,GIE
banksel PPSLOCK
movlw 0x55 ;Required sequence, next 5 instructions
movwf PPSLOCK
movlw 0xAA
movwf PPSLOCK 
bcf PPSLOCK, PPSLOCKED ;Set PPSLOCKED bit to disable writes or clear PPSLOCKED bit to enable writes
 
 
 
 
 
 
 
;****************************** I2C Input PPS Config ************************;
banksel SSP2CLKPPS 
movlw b'00001101' 
movwf SSP2CLKPPS ;Set SCL2 pin to RB5
movlw b'00001111' 
movwf SSP2DATPPS ;Set SDA2 pin to RB7
;************************* I2C Output PPS Config ************************;
banksel RB7PPS
movlw 0x16 
movwf RB7PPS ;Set SDA2 pin to RB7
movlw 0x15 
movwf RB5PPS ;Set SCL2 pin to RB5
 
 
 
 
 
 
 
banksel INTCON
bcf INTCON, GIE
banksel PPSLOCK
movlw 0x55 ;Required sequence, next 5 instructions
movwf PPSLOCK
movlw 0xAA
movwf PPSLOCK ;Set PPSLOCKED bit to disable writes or clear PPSLOCKED bit to enable writes
bsf PPSLOCK, PPSLOCKED
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
I2C config
 

 
 
 
 
 
 
 
;****************************** I2C Config **********************************; 
banksel SSP2CON1
movlw b'00101000' 
; 0------- WCOL - no collision
; -0------ SSPOV - no overflow
; --1----- SSPEN - enable SDA and SCL ports
; ---0---- CKP - not used in master mode
; ----1000 SSPM<3:0> I2C Master mode, clock = FOSC/(4*(SSPxADD+1))
movwf SSP2CON1
banksel SSP2STAT
movlw b'10110101' ;I2C sleep rate diabled for 100k, disable smbus, last byte data, stop bit deteted last, stat bit not dected last 
movwf SSP2STAT
banksel SSP2ADD ;baud rate divider if master, bit 7:1 slave address if slave (bit 0 don't care)
movlw h'09' ; calculate setting for I2C baud rate 
movwf SSP2ADD
;****************************** I/O Config **********************************; 
banksel TRISA
movlw b'00100000' ;Set RA5 input, others outputs
movwf TRISA 
banksel TRISB
movlw b'00000000' ;Set all outputs
movwf TRISB 
movlw b'00001000' 
movwf TRISC 
;****************************** ADC Config **********************************;
banksel ANSELA
clrf ANSELA ;Disable ADC ANSELA
clrf ANSELB  ;Disable ADC ANSELB
clrf ANSELC ;Disable ADC ANSELC
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
banksel INTCON ;enable PEIE and GIE
bsf INTCON, PEIE
bsf INTCON, GIE

banksel PIR3
bcf PIR3, SSP2IF ; I2C module is ready, clear flag.

banksel PIE3
bsf PIE3, SSP2IE ;enable I2C interrupts
 
 
 
 
 
 
 

 
I am then calling the start condition, followed by a write.
 

 
 
 
banksel temp_address
clrf temp_address
movlw h'2A'
movwf temp_address
 
 
 
 
 
 
 
Loop
call WrtStart ;Start Bit
call check_idle  
call SendI2CWrt ; Send Address Byte
 
 
 
call check_idle  
 
 
 
call WrtStop ; Send Stop Bit
 
 
 
 
 
 
 
 
 
 
 
goto  Loop
 
 
 
 
 
 
 
WrtStart

banksel SSP2CON2 ; select SFR bank
bsf SSP2CON2,SEN ; initiate I2C bus start condition
banksel PIR3
btfss PIR3,SSP2IF
goto $-1
return 
 
 
 
 
 
 
 
SendI2CWrt
banksel temp_address ; select GPR bank
movfw temp_address
banksel SSP2CON2
bcf SSP2CON2,RCEN
banksel SSP2BUF ; select SFR bank
movwf SSP2BUF ; initiate I2C bus write condition
banksel PIR3
clrf PIR3
btfss PIR3, SSP2IF
goto $-1 
return
 
 
 
 
 
 
 
check_idle
banksel SSP2STAT
btfsc SSP2STAT, R_W ;transmit in progress?
goto $-1
movf SSP2CON2, 0 ;get copy of SSP2CON2
andlw 0x1F ;mask non-status
btfss STATUS, Z
goto $-3 ;bus busy, test again
banksel PIR3
bcf PIR3,3
return
 
 
 
 
 
 
 
WrtStop
banksel SSP2CON2 ; select SFR bank
btfss SSP2CON2,ACKSTAT ; test for acknowledge from slave
goto noerror ;bypass setting error flag
banksel eflag_event ;select GPR bank
bsf eflag_event,ack_error ;set acknowledge error

noerror
banksel SSP2CON2 ; select SFR bank
bsf SSP2CON2,PEN ; initiate I2C bus stop condition
return ;
 
 
 
 
 
 
 
end
 
 
 
 
 
 
 

#1

3 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28324
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: MSSP Configuration, no waveforms present 2020/05/31 15:41:12 (permalink)
    0
    The only thing that jumps out at me is that you are setting SDA and SCL (RB5 and RB7) as outputs, when the datasheet tells you to set them as inputs.
     
    Not your problem, but note:
    [1] Please always specify the full part number. I assume "18446" means a "PIC16F18446".
    [2] You don't need to BANKSEL INTCON. That is a global register.
    [3] You are enabling interrupts, but don't show any Interrupt Service Routine. Do NOT enable them without an ISR. You don't need them enabled to poll the interrupt flags.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    baseball07
    Starting Member
    • Total Posts : 54
    • Reward points : 0
    • Joined: 2010/09/17 17:19:23
    • Location: 0
    • Status: offline
    Re: MSSP Configuration, no waveforms present 2020/06/01 07:12:06 (permalink)
    0
    Thanks for the feedback.  I have PPS configured for Input and Output, and just changed the pins TRIS to input - this was the problem.
      
    1.  Noted
    2.  Noted
    3.  Noted, all interrupts turned off.  
    post edited by baseball07 - 2020/06/01 07:19:44
    #3
    bkamen
    Super Member
    • Total Posts : 835
    • Reward points : 0
    • Joined: 2010/01/26 12:39:27
    • Location: Central Illinois, USA
    • Status: offline
    Re: MSSP Configuration, no waveforms present 2020/06/05 09:05:27 (permalink)
    0
    Don't forget to mark your post as "[Solved]"

    Cheers,

     -Ben
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5