• AVR Freaks

Helpful ReplySMBus transmit problem

Author
GunkutA
Junior Member
  • Total Posts : 107
  • Reward points : 0
  • Joined: 2019/01/10 00:09:38
  • Location: 0
  • Status: offline
2019/04/04 23:47:43 (permalink)
0

SMBus transmit problem

Hello I am trying to communicate with a device by using SMBus. I use PIC18F26K83. When I try to transmit a byte, TXBE bit (Transmit buffer empty status) never gets 1. My code is like this:
 
 
 
SMBus initialization:
 
 void SMBus_Setup(){

   LATB=0x00;
   TRISB=0xF9;
   //TRISB=0x06;
    ANSELB = 0xF9;
     ODCB2_BIT = 1; //Open drain control//sink current only
 ODCB1_BIT = 1;
 WPUB2_BIT = 0; // Weak Pull-up disabled
 WPUB1_BIT = 0;
  RB1I2C = 0x02; //Threshold =2.1 V
 RB2I2C= 0x02; //Threshold= 2.1V

 //Commentle alti
 SLRCONB.B2 =0; //Port pin slews at maximum rate
 SLRCONB.B1 =0;
 
RB1PPS= 0b00100011; // RB1= I2C2 (SCL) output.
RB2PPS= 0b00100100; //RB2= I2C(SDA) output.
I2C2SCLPPS = 0b00001001; // RB1 I2C2 Clock
I2C2SDAPPS= 0b00001010; // RB2 I2C2 Data


 
 I2C2CON0.B7 =0; // I2C2 disabled
I2C2BTO =0;
 I2C2PIE =0;
 I2C2PIR =0;
 I2C2ERR =0;
 I2C2STAT0 =0;
 I2C2STAT1 =0;
 



 

I2C2CON0=0x04;
              I2C2CON1=0X80;
           I2C2CON2=0x21;
    
    // I2C2 CLOCK EDIT EDSIT EDIT EDIT THIS ONEEEE UGHHHH
       I2C2CLK.B3 =0;
       I2C2CLK.B2 =0;
       I2C2CLK.B1 =0;
       I2C2CLK.B0 =1; //0010 HFINT OSC 0001 FOSC
                      //I2C FREQUENCY=1000/5=200KHz
                      //FME=0 MEANS DIVISION=5
        I2C2ADR0 =0; // ADR<7:0> *addr buf disabled
 I2C2ADR1 =0; // ADR<7:1>
 I2C2ADR2 =0; // ADR<7:0>
 I2C2ADR3 =0; // ADR<7:1>
 I2C2ADB0 =0; // ADB<7:0>
 I2C2ADB1 =0; // ADB<7:0>
 I2C2CNT =0; // CNT<7:0>
 I2C2RXB =0; // RXB<7:0>
 I2C2TXB =0; // TXB<7:0>
     I2C2CON0.B7=1; //MODULE ENABLE

 }

 
Transmit part:
 
void SMBus_Data(){
    LATA2_BIT=0;
    I2C2STAT1.B2=1;// CLRBF=1, EMPTIES TRANSMIT BUFFER,i.e. TXBE=1
  I2C2CON0.B6=0; //RSEN=0;

             //BUS FREE? I2C1
   while (!I2C2STAT0.B7) { } // BUS FREE BFRE=1

 
 
 
 
 // I2C2CON0.B5=1; //MASTER START BIT
  I2C2CNT=2; //BYTE COUNT REGISTER

                I2C2ADB1=0x16; //Address for smart battery
                I2C2TXB =0x0D; //Relative SOC

               //******START**********
               I2C2CON0.B5=1; //MASTER START BIT
                LATA.RA2=0;

          while(!I2C2Stat1.B5){
            LATA.RA2=1;
              delay_ms(99999);}
}

 
And it gets stuck at while(!I2C2Stat2.B5) part.
 
Here is the oscilloscope image (Blue one is SCL and yellow one is SDA pin) and also circuit schematic. (see I use RB1 & RB2 for SMBus communication.) I am not sure about pull up resistor values and SCL signal is not %50 duty cycle. Would that cause the problem?
 
 
 
 
 
post edited by GunkutA - 2019/04/05 03:43:09

Attached Image(s)

#1
qhb
Superb Member
  • Total Posts : 9985
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: offline
Re: SMBus transmit problem 2019/04/08 03:31:54 (permalink) ☄ Helpfulby GunkutA 2019/04/08 04:57:24
+1 (1)
I think you have to set the PPS output function for both SDA and SCL.
You can use the default SDA and SCL PPS input functions, but there is no default PPS out assignment.
I agree, the datasheet for this PIC does not make this point clear.
 

Only 15 to go...
#2
Jump to:
© 2019 APG vNext Commercial Version 4.5