• AVR Freaks

Hot!Can't get data from ADS1115 I2C and PIC 18f2550.

Author
MarcoRM
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2018/11/05 12:10:58
  • Location: 0
  • Status: offline
2018/11/08 16:19:05 (permalink)
0

Can't get data from ADS1115 I2C and PIC 18f2550.

Hello Everyone.
 
I'm on a project using pic 18f2550 and ads1115. I want to get analog data from ads1115 and send it to pc via usart. I haven't had any success yet because I must be forgotten something. As you will see, I tried to write some code, but I think I've made several mistakes I can't find. I've marked with asterisks blocks I can't improve.
 
Main function:
 
void I2C_init();
void I2C_wait();
void I2C_start_com();
void I2C_restart_com();
void I2C_stop();
unsigned char I2C_write(unsigned char);
unsigned char I2C_read();

//********************************************************
void ADS1115_config();
unsigned int ADS1115_read();
//********************************************************

void Eusart_init();
void putcUSART(char c);
void putsUSART(char *data);
void putrsUSART(const char *data);

//********************************************************
unsigned int conversion;
unsigned char buffer_conversion[8];
//********************************************************

int main(int argc, char** argv)
{
    OSCCONbits.IRCF=0b110;
    ADCON0bits.ADON=0;
    ADCON1bits.PCFG=0x0F;
    I2C_init();
    ADS1115_config();
    Eusart_init();
    while(1)
    {
        //********************************************************
        conversion=ADS1115_read();
        sprintf(buffer_conversion,"%u",conversion);
        putsUSART(buffer_conversion);
        putrsUSART("\n");
        __delay_ms(25);
        //********************************************************
    }
    return (EXIT_SUCCESS);
}

 
I2C Block:
 
void I2C_init()
{
    TRISBbits.TRISB0 = 1; //Setting as input as given in datasheet
    TRISBbits.TRISB1 = 1; //Setting as input as given in datasheet
    SSPSTAT = 0b10000000;
    SSPCON1 = 0b00101000; //SSP module como master
    SSPCON2 = 0b00000000;
    SSPADD = 9; //Setting Clock Speed 100kbps
}

void I2C_wait()
{
    while ((SSPCON2 & 0b00011111) || (SSPSTAT & 0b00000100)); //Transmit is in progress
}

void I2C_start_com()
{
    I2C_wait();
    SSPCON2bits.SEN = 1; //Initiate start condition
}

void I2C_stop()
{
    I2C_wait();
    SSPCON2bits.PEN = 1;
}

void I2C_restart_com()
{
    I2C_wait();
    SSPCON2bits.RSEN=1;
}

unsigned char I2C_write(unsigned char wdata)
{
    I2C_wait();
    SSPBUF = wdata; //Write data to SSPBUF
    return ACKSTAT;
}

unsigned char I2C_read()
{
    unsigned char rdata;
    I2C_wait();
    SSPCON2bits.RCEN = 1; //Receive mode enabled
    I2C_wait();
    rdata = SSPBUF; //Read data from SSPBUF.
    I2C_wait();
    SSPCON2bits.ACKDT = 1; //Acknowledge bit
    SSPCON2bits.ACKEN = 1; //Acknowledge sequence
    return rdata;
}

 
ADS1115 Block:
 
void ADS1115_config()
{
    I2C_write(0b10010000);//Communicate to slave address
    I2C_wait();
    I2C_write(0b00000001);//Command to config registers
    I2C_wait();
    I2C_write(0b10000000);//PGA: +-6.144V, Inputs: default (A0), continuous conv. mode
    I2C_wait();
    I2C_write(0b10000011);//128 SPS, Traditional comparator, active low, nonlatching, dis. ALERT/RDY
}

//********************************************************
unsigned int ADS1115_read()
{
    I2C_start_com();
    I2C_write(0b10010000);
    I2C_wait();
    I2C_write(0b00000000);
    I2C_wait();
    I2C_restart_com();
    I2C_wait();
    I2C_write(0b10010001);
    I2C_wait();
    unsigned int adc;
    adc = I2C_read(1);
    adc = adc<<8;
    adc = adc|I2C_read(0);
    I2C_stop();
    I2C_wait();
    return adc;
}

 
USART Block:
 
void Eusart_init()
{
    TRISCbits.TRISC7 = 1; // RX
    TRISCbits.TRISC6 = 0; // TX
    TXSTA = 0b00100100;
    RCSTA = 0b10010000;
    SPBRG=103;
    SPBRGH=0;
    BAUDCON = 0b00001000;
}

void putcUSART(char c)
{
    while(!PIR1bits.TXIF);
    TXREG = c;
}

void putrsUSART(const char *data)
{
    do {
        while(TXSTA1bits.TRMT == 0);
        putcUSART(*data);
    } while( *data++ );
}

void putsUSART( char *data)
{
    do {
        while(TXSTA1bits.TRMT == 0);
        putcUSART(*data);
    } while( *data++ );
}

 
I will appreciate any help to make progress while trying to answer this.
 
Thanks for all your contributions.
#1

12 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/11/08 16:43:37 (permalink)
    +1 (1)
    RB0 and RB1 are also analog pins.
    I cannot see any code switching them to digital mode.
     
     

    Nearly there...
    #2
    MarcoRM
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/11/05 12:10:58
    • Location: 0
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/11/08 18:50:13 (permalink)
    0
    Hi sir:
     
    In this part of the code it is switched to digital:
     
     ADCON0bits.ADON=0;
     ADCON1bits.PCFG=0x0F;
    #3
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/11/08 18:59:40 (permalink)
    +1 (1)
    Sorry, you're right.
    It's harder to spot on these older parts that don't have ANSEL registers, especially when there's no comment on the line. :)
     
    I see one problem in your "write" routine
    unsigned char I2C_write(unsigned char wdata)
    {
        I2C_wait();
        SSPBUF = wdata; //Write data to SSPBUF
        return ACKSTAT;
    }

    There should be a wait before you tried to read the ACKSTAT bit. You are reading it before the transfer has happened.
    Try:
    unsigned char I2C_write(unsigned char wdata)
    {
        I2C_wait();
        SSPBUF = wdata; //Write data to SSPBUF
        I2C_wait();    // wait until transfer completes
        return ACKSTAT;
    }

    Also, you are never checking the value returned by this function. Especially when you send the first byte (the slave address), you should make sure you get an ACK back. If you don't, the slave is not hearing you, and everything else is pointless.
     

    Nearly there...
    #4
    MarcoRM
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/11/05 12:10:58
    • Location: 0
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/11/09 12:34:58 (permalink)
    0
    Thanks for your response,qhb. I will apply your advices.
     
    Do you refer to these codes for ACK and NAK?:
     
    void I2C_Master_ACK() {
        ACKDT = 0; // Acknowledge data bit, 0 = ACK
        ACKEN = 1; // ACk data enabled
        I2C_Master_Wait();
    }

    void I2C_Master_NAK() {
        ACKDT = 1; // Acknowledge data bit, 1 = NAK
        ACKEN = 1; // ACK data enabled
        I2C_Master_Wait();
    }

     
    How should I introduce into my code? I think you said they must go between reading from ads.
     
    Thanks again for another response. 
    #5
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/11/09 14:12:01 (permalink)
    0
    MarcoRM
    ...
    Do you refer to these codes for ACK and NAK?:
     

    No. That is the code to send an ACK or NAK.
    I already showed you exactly what to do to actually read the ACK/NAK correctly inside I2C_Write().
    You now need to look at the value returned by your calls to I2C_Write().
    Also, I noticed you never send START or STOP when you configure the ADC
    e.g. here:
    void ADS1115_config()
    {
        I2C_start_com();
        if (I2C_write(0b10010000))    //Send slave address
        {    //here if slave address did not get ACK response
            I2C_stop();    //slave is not responding, release bud
            return;    //abort
        }
        I2C_wait();
        I2C_write(0b00000001);//Command to config registers
        I2C_wait();
        I2C_write(0b10000000);//PGA: +-6.144V, Inputs: default (A0), continuous conv. mode
        I2C_wait();
        I2C_write(0b10000011);//128 SPS, Traditional comparator, active low, nonlatching, dis. ALERT/RDY
        I2C_stop();
    }

    All your questions sound like someone who is trying to muddle through with no understanding of the I2C protocol.
    You really do need to understand how each transaction starts with a START condition, ends with a STOP condition, and every byte transfer is ACKed or NAKed.
    You should have a read of:
    https://en.wikipedia.org/wiki/I%C2%B2C
    and
    https://www.nxp.com/docs/en/user-guide/UM10204.pdf (Official I2C specification)
     
    post edited by qhb - 2018/11/09 14:13:24

    Nearly there...
    #6
    MarcoRM
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/11/05 12:10:58
    • Location: 0
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/11/09 14:48:16 (permalink)
    0
    Hi,qhb
     
    I'm sorry if my questions sound so inquisitive, it seems I need to review the protocol. When I finish this, I'll post the improved code.
     
    Thanks for your attention and time. 
    #7
    MarcoRM
    New Member
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/11/05 12:10:58
    • Location: 0
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/12/27 16:15:10 (permalink)
    0
    I finally finished my project. This is the code I implemented for using ads1115 with 18f2550:
     

    #include <xc.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <pic18f2550.h>
    #define _XTAL_FREQ 4000000UL
    // CONFIG1L
    #pragma config PLLDIV = 1 // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
    #pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
    #pragma config USBDIV = 1 // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
    // CONFIG1H
    #pragma config FOSC = INTOSC_XT // Oscillator Selection bits (Internal oscillator, XT used by USB (INTXT))
    #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
    #pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
    // CONFIG2L
    #pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
    #pragma config BOR = ON // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
    #pragma config BORV = 3 // Brown-out Reset Voltage bits (Minimum setting 2.05V)
    #pragma config VREGEN = OFF // USB Voltage Regulator Enable bit (USB voltage regulator disabled)
    // CONFIG2H
    #pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
    #pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
    // CONFIG3H
    #pragma config CCP2MX = ON // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
    #pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
    #pragma config LPT1OSC = OFF // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
    #pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
    // CONFIG4L
    #pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
    #pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
    #pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
    // CONFIG5L
    #pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
    #pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
    #pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
    #pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)
    // CONFIG5H
    #pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
    #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
    // CONFIG6L
    #pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
    #pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
    #pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
    #pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)
    // CONFIG6H
    #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
    #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
    #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
    // CONFIG7L
    #pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
    #pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
    #pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
    #pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)
    // CONFIG7H
    #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
    void I2C_Master_Init();
    void I2C_Master_Wait();
    void I2C_Master_Start();
    void I2C_Master_Stop();
    void I2C_Master_RepeatedStart();
    void I2C_Master_Write(unsigned d);
    unsigned short I2C_Master_Read(unsigned short a);
    //********************************************************
    void ADS1115_config();
    float ADS1115_read();
    //********************************************************
    void Eusart_init();
    void putcUSART(char c);
    void putsUSART(char *data);
    void putrsUSART(const char *data);
    //********************************************************
    float dato=0;
    char buffer_conversion[8];
    //********************************************************
    int main(int argc, char** argv)
    {
    OSCCONbits.IRCF=0b110;
    ADCON0bits.ADON=0;
    ADCON1bits.PCFG=0x0F;
    I2C_Master_Init();
    ADS1115_config();
    Eusart_init();
    while(1)
    {
    //********************************************************
    dato=ADS1115_read();
    sprintf(buffer_conversion,"%4.1f",dato);
    putsUSART(buffer_conversion);
    putrsUSART("\n");
    //********************************************************
    }
    return (EXIT_SUCCESS);
    }
    //_____________________I2C BLOCK________________________//
    void I2C_Master_Init()
    {
    TRISBbits.TRISB0 = 1; //Setting as input as given in datasheet
    TRISBbits.TRISB1 = 1; //Setting as input as given in datasheet
    SSPSTAT = 0b10000000;
    SSPCON1 = 0b00101000; //SSP module como master
    SSPCON2 = 0b00000000;
    SSPADD = 9; //Setting Clock Speed 100kbps
    }
    void I2C_Master_Wait()
    {
    while ((SSPCON2 & 0b00011111) || (SSPSTAT & 0b00000100)); //Transmit is in progress
    }
    void I2C_Master_Start()
    {
    I2C_Master_Wait();
    SSPCON2bits.SEN = 1; //Initiate start condition
    }
    void I2C_Master_Stop()
    {
    I2C_Master_Wait();
    SSPCON2bits.PEN = 1;
    }
    void I2C_Master_RepeatedStart()
    {
    I2C_Master_Wait();
    SSPCON2bits.RSEN=1;
    }
    void I2C_Master_Write(unsigned d)
    {
    I2C_Master_Wait();
    SSPBUF = d; //Write data to SSPBUF
    }
    unsigned short I2C_Master_Read(unsigned short a)
    {
    unsigned short temp;
    I2C_Master_Wait();
    SSPCON2bits.RCEN = 1; //Receive mode enabled
    I2C_Master_Wait();
    temp = SSPBUF; //Read data from SSPBUF.
    I2C_Master_Wait();
    SSPCON2bits.ACKDT = (a)?0:1; //Acknowledge bit
    SSPCON2bits.ACKEN = 1; //Acknowledge sequence
    return temp;
    }
    //_______________ADS1115 CONFIG AND DATA BLOCK__________________//
    void ADS1115_config()
    {
    I2C_Master_Start();
    I2C_Master_Wait();
    I2C_Master_Write(0b10010000);
    I2C_Master_Wait();
    I2C_Master_Write(0b00000001);//Command to config registers
    I2C_Master_Wait();
    I2C_Master_Write(0b10000000);//PGA: +-6.144V, Inputs: default (A0), continuous conv. mode
    I2C_Master_Wait();
    I2C_Master_Write(0b10000011);//128 SPS, Traditional comparator, active low, nonlatching, dis. ALERT/RDY
    I2C_Master_Stop();
    I2C_Master_Wait();
    }
    //********************************************************
    float ADS1115_read()
    {
    unsigned int datah;
    unsigned int datal;
    float data;
    I2C_Master_Start();
    I2C_Master_Wait();
    I2C_Master_Write(0b10010000);
    I2C_Master_Wait();
    I2C_Master_Write(0b00000000);
    I2C_Master_Wait();
    I2C_Master_RepeatedStart();
    I2C_Master_Wait();
    I2C_Master_Write(0b10010001);
    I2C_Master_Wait();
    datah = I2C_Master_Read(1);
    datal = I2C_Master_Read(0);
    data=((datah<<8)|datal)*0.1875/1000;
    I2C_Master_Stop();
    I2C_Master_Wait();
    return data;
    }
    //********************************************************
    //_______________USART COMMUNICATION BLOCK__________________//
    void Eusart_init()
    {
    TRISCbits.TRISC7 = 1; // RX
    TRISCbits.TRISC6 = 0; // TX
    TXSTA = 0b00100100;
    RCSTA = 0b10010000;
    SPBRG=103;
    SPBRGH=0;
    BAUDCON = 0b00001000;
    }
    void putcUSART(char c)
    {
    while(!PIR1bits.TXIF);
    TXREG = c;
    }
    void putrsUSART(const char *data)
    {
    do {
    while(TXSTA1bits.TRMT == 0);
    putcUSART(*data);
    } while( *data++ );
    }
    void putsUSART( char *data)
    {
    do {
    while(TXSTA1bits.TRMT == 0);
    putcUSART(*data);
    } while( *data++ );
    }

     
    Thanks. This question is answered.
    #8
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/12/27 16:51:02 (permalink)
    0
    A few points:
    Change
    #include <xc.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    #include <pic18f2550.h>

    to
    #include <xc.h>
    #include <stdio.h>

    xc.h has already included pic18f2550.h for you, you're just doing it a second time.
    You don't need any of the other header files for this program.
     
    Change
    int main(int argc, char** argv) 

    to
    void main (void)

    There is no operating system passing parameters to your program, or accepting a return value from it
     
    Delete
     return (EXIT_SUCCESS);

    As above
     
    Delete
    void putrsUSART(const char *data)
    {
     do {
     while(TXSTA1bits.TRMT == 0);
     putcUSART(*data);
     } while( *data++ );
    }

    You do not need a separate function to handle ROM strings in XC8. It was C18 that required special handling of ROM strings, XC8 does it automatically, so just use putsUSART() for all your output.
     (If you renamed putcUSART() to putch(), then you could just use the library function puts() instead.)
     
    Change:
    void putsUSART( char *data)
    {
     do {
     while(TXSTA1bits.TRMT == 0);
     putcUSART(*data);
     } while( *data++ );
    }

    To:
    void putsUSART( char *data)
    {
      while( *data ) {
        putcUSART(*data++);
      }
    }

    You don't need to wait for TRMT. The wait for TXIF inside putcUSART() does all the required waiting.
    Your loop structure was sending the terminating NULL character as well, which is rarely desirable.
     
    Also, this code is still never checking the ACK replies from the Slave, which I commented on back in post#4
     
    post edited by qhb - 2018/12/27 16:53:19

    Nearly there...
    #9
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/12/27 16:56:26 (permalink)
    0
    n.b. extending what I said about naming your character output function as putch().
    If you do that, then you don't need to use sprintf(), you can just use printf() directly.
     

    Nearly there...
    #10
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/12/27 19:44:57 (permalink)
    0
    Assuming you are getting full 16 bit data from the ADC, your maximum
    ((datah<<8)|datal
    value is 0xFFFF = 65535
    65535 *0.1875/1000 = 12.29
    so why is the output format "4.1f" ?
    i.e. why output 4 leading digits when there will only ever be 1 or 2?
     
    You could use 32 bit integer math to avoid floating point
    unsigned long acc;
    unsigned int intpart;
    unsigned int fracpart;
     
    acc = ((datah<<8)|datal;
    acc *= 3146; //=0x1000000 * 0.1875/1000
    intpart = acc / 0x1000000;    // integer part
    fracpart = 10 * (acc & 0xffffff) / 0x1000000;  //first decimal place
    printf ("%2d.%1d",intpart,fracpart);

    This hugely reduces the size of your code.
     
    post edited by qhb - 2018/12/27 19:46:17

    Nearly there...
    #11
    simong123
    Lab Member No. 003
    • Total Posts : 1293
    • Reward points : 0
    • Joined: 2012/02/07 18:21:03
    • Location: Future Gadget Lab (UK Branch)
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/12/27 20:10:18 (permalink)
    0
    qhb
    so why is the output format "4.1f" ?
    i.e. why output 4 leading digits when there will only ever be 1 or 2?
     

    That doesn't output 4 leading digits. The 4 is the minimum width including all digits and the decimal point.
    I.e.:-
    The value 1.229 will be displayed as " 1.2" (note leading space, width=4)
    The value 12.29 will be displayed as "12.3" (width=4)
    The value 122.9 will be displayed as "122.9" (note width now 5)
     
     
    #12
    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Can't get data from ADS1115 I2C and PIC 18f2550. 2018/12/27 20:15:48 (permalink)
    0
    Thanks Simon, bit of brain fade there, as I almost always avoid floating point. :)
    As the value will never exceed 12.29, the third case will never apply here.

    Nearly there...
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5