Building an I2C monitor ... but i think it is not Slave....


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Building an I2C monitor ... but i think it is not Slave....

    While speed-optimizing an IRQ Bit-bang routine i am working on now , i though it would be useful to use the EUSART Synchronous Slave Reception mode (asuming using the 2 EUSART pins of course).
    Eg.

    On SDA (P/N) /SCL (P only) port change Interrupt :
    1. Check if STARTbit
    2. If it is STARTbit then Enable the EUSART in Slave RX mode (and stay in IRQ routine ! , don't leave out!)
    3. EUSART gets the 8 bit BYTE (done in hardware , no bitbanging and bit-shifting )
    4. Ignore the 9th (N)ACK bit (i don't need it...)
    5. Resume

    6. In the next interrupt i will check if i get a STOP or a RESTART ...and so on...

    I guess i am not mistaken ....
    Last edited by LakisFM1; - 4th March 2012 at 09:40.

  2. #2
    Join Date
    Feb 2010
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Building an I2C monitor ... but i think it is not Slave....

    I am happy to say that the bit-banging I2C monitor is done.

    It is written all in PBP , and uses interrupts for the input-bit sensing using a...12F1822 at... 32MHz of course.

    Tommorow i will post the code here , since i dont' have it now here.

    Cheers!

  3. #3
    Join Date
    Feb 2010
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Building an I2C monitor ... but i think it is not Slave....

    Code:
    ASM
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
     __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_19 & _LVP_OFF
    
    ENDASM
     
      DEFINE OSC 32
      
        TX  VAR PORTA.0 
        SCL VAR PORTA.1 
        SDA VAR PORTA.2 
    
        SCLB VAR PORTAB.1
        SDAB VAR PORTAB.2
        SCLF VAR IOCAF.1
        SDAF VAR IOCAF.2
                
        BIT_COUNTER VAR BYTE
        STOP_COUNTER VAR BYTE
        BYTE_READY VAR BIT
        BYTEINT VAR BYTE
        BYTEINT2 VAR BYTE
        BYTEINB VAR BYTE
        BYTEIN VAR BYTE[30]  
        PORTAB VAR BYTE            
        BYTE_COUNTER VAR BYTE
        BYTES_RECEIVED VAR BYTE
        STOPFLAG VAR BIT
    
        OSCCON = %01110000         
        IOCAN = %00000100
        IOCAP = %00000110 
        
        ON INTERRUPT GoTo INT   ' Declare interrupt handler routine
     
     START:    
        PAUSE_1000
     
        OPTION_REG.7 = 1         ' DISABLE PORTB PULLUPS
           
        PORTA = %00000110        ' SWAP PORTA.0 /PORTA.2 FOR SMALL PCB
        TRISA = %00001110        ' SWAP PORTA.0 /PORTA.2 FOR SMALL PCB
        ANSELA = $00             ' MAKE ALL INPUTS DIGITAL I/O PINS
        WPUA = $00
       
        BIT_COUNTER = 0
        BYTE_COUNTER = 0
        
        INTCON = %10001000        ' Enable GLOBAL AND IOCHANGE interrupts  
        
    MAIN_LOOP:
          
        IF STOPFLAG = 1 THEN   
        '/ Here we have the received bytes in the array BYTEIN(x)
        ' The size of the array is in the variable BYTES_RECEIVED.
        ' You have to process them  and then ...
        BYTE_COUNTER = 0 ' in order to get the next bytes
        ENDIF
      
        GOTO MAIN_LOOP
        
        
       
    '============================================================================
    '================ BIT BANGING interrupt handler  ============================
    '============================================================================
    
    Disable                                ' Don't check for interrupts in this section
    
    INT:                                
        PORTAB = PORTA                  'Buffer the STATUS OF THE PORT
        
        '------------------------- ignore errory databits ------------------------
        'using the I2CWRITE command of PBP i got an errory SDA pulse ...
        'using the next line i ignore this error-y line ...
        'for other uses you may ommit it .
    
        IF SCLB = 0 THEN IOCAF = $00 : RESUME ' IGNORE WHEN CLK = 0 
    
        '-----------------------receive data bit -----------------------------------    
            
        if SCLF = 1 THEN                'CLK_FLAG SET : IT IS DATA !
           
        '----------------------- store byte ----------------------------------------
        
         IF BIT_COUNTER.3 = 1 THEN       ' IF WE GET 8 BITS RESET BITCOUNTER
          BIT_COUNTER.3 = 0              
       
          BYTEIN(BYTE_COUNTER) = BYTEINT ' AND STORE THE BYTE
          BYTE_COUNTER = BYTE_COUNTER + 1
       
          IOCAF.1 = 0                     ' CLEAR INT ON CHANGE FLAGS
          RESUME 
         ENDIF  
         
        ' ------------------------- receive bit ------------------------------------     
        
         BYTEINT = (BYTEINT << 1)                
         BYTEINT.0 = PORTAB.2
         BIT_COUNTER = BIT_COUNTER + 1 
             
         IOCAF.1 = 0                     ' CLEAR INT ON CHANGE FLAGS
         RESUME
        ENDIF  
      
        ' --------------------start bit-----------------------------------------------
        IF SDAB = 0 THEN 
          BIT_COUNTER = 0 
          IOCAF.2 = 0                     ' CLEAR INT ON CHANGE FLAGS
          RESUME
         ENDIF
        '---------------------stop bit ----------------------------------------------
                
          STOPFLAG = 1 
          BYTES_RECEIVED =  BYTE_COUNTER
          'BYTE_COUNTER = 0               'nevermind BYTECOUNTER WILL RESET AT THE NEXT START BIT ANYWAY
          IOCAF.2 = 0                     ' CLEAR INT ON CHANGE FLAGS
          RESUME  
    ENABLE
    
    End
    Last edited by mackrackit; - 14th March 2012 at 05:07.

  4. #4
    Join Date
    Feb 2010
    Posts
    30


    Did you find this post helpful? Yes | No

    Default Re: Building an I2C monitor ... but i think it is not Slave....

    I must note i used a 12F1822 @32 MHz and the I2Cbus was running at slow speed !. I don't think the code is fast enough for a 400KHz bus!

  5. #5
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default Re: Building an I2C monitor ... but i think it is not Slave....

    For those who are interested, I placed my implementation here: http://www.electro-tech-online.com/b...mitations.html

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts