This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ads1115

Other Parts Discussed in Thread: ADS1115, MSP430G2231

有用msp430调过ads1115驱动模块吗,能发一份资料吗,一直调不出来

  • 没有用过这个ADC,看了一下资料,是IIC接口的,配置起来不是太复杂,先看看您用的MCU的IIC部分资料,然后根据ADC的地址,寄存器操作等进行控制就行了

  • 可以参考下下面这段:

    这是写8bit的,修改成data有16bit即可。

    //******************************************************************************

    //  MSP430F20xx Demo - I2C Master Receiver, single byte

    //

    //  Description: I2C Master communicates with I2C Slave using

    //  the USI. Slave data should increment from 0x00 with each transmitted byte

    //  which is verified by the Master.

    //  LED off for address or data Ack; LED on for address or data NAck.

    //  ACLK = n/a, MCLK = SMCLK = Calibrated 1MHz

    //

    //  ***THIS IS THE MASTER CODE***

    //

    //                  Slave                      Master

    //          (msp430x20x3_usi_09.c)

    //               MSP430F20x2/3              MSP430F20x2/3

    //             -----------------          -----------------

    //         /|\|              XIN|-    /|\|              XIN|-

    //          | |                 |      | |                 |

    //          --|RST          XOUT|-     --|RST          XOUT|-

    //            |                 |        |                 |

    //      LED <-|P1.0             |        |                 |

    //            |                 |        |             P1.0|-> LED

    //            |         SDA/P1.7|------->|P1.7/SDA         |

    //            |         SCL/P1.6|<-------|P1.6/SCL         |

    //

    //  Note: internal pull-ups are used in this example for SDA & SCL

    //

    //  Z. Albus

    //  Texas Instruments Inc.

    //  May 2006

    //  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A

    //******************************************************************************

    #include  <msp430g2231.h>

    #define DELAY_START_CYCLES 20

    //void i2c_usi_mst_wait_usi_cnt_flag();

    void FORCING_SDA_HIGH(void)          

           {                            

             USISRL = 0xFF;            

             USICTL0 |= USIGE;          

             USICTL0 &= ~(USIGE+USIOE);

           }

    void FORCING_SDA_LOW(void)        

           {                        

             USISRL = 0x00;          

             USICTL0 |= USIGE+USIOE;

             USICTL0 &= ~USIGE;      

           }

    void DELAY(int delay)

    {

      int i;

      for (i = 0; i < delay; i++);

    }

    ////////////////////////////////////////////////////////////////////////////////////////////

    char addr = 0xC0;                  // Address is 0x48 << 1 bit + 0 for Write

    char reg = 0x08;

    char data = 0xA0;                  // Variable for received data

    char RW;

    int i =0;

    void I2Cwrite(char,char,char);

    void I2Cread(char, char);

    int I2C_State = 0;                     // State variable

    // function to generate I2C REPEATED START condition

    void i2c_usi_mst_gen_repeated_start(void)

    {

     USICTL0 |= USIOE;

     USISRL = 0xFF;

     USICNT = 1;

     // wait for USIIFG is set

     //i2c_usi_mst_wait_usi_cnt_flag();

     // small delay

     //DELAY(DELAY_START_CYCLES);

    DELAY(50);

     // pull down SDA to create START condition

     FORCING_SDA_LOW();

     // small delay

     //DELAY(DELAY_START_CYCLES);

    }

    void main(void)

    {

     volatile unsigned int i;             // Use volatile to prevent removal

     WDTCTL = WDTPW + WDTHOLD;            // Stop watchdog

     if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)                                    

     {  

       while(1);                          // If calibration constants are erased

                                          // do not load, trap CPU!!

     }

     BCSCTL1 = CALBC1_1MHZ;               // Set DCO

     DCOCTL = CALDCO_1MHZ;

     P1OUT = 0xC0;                        // P1.6 & P1.7 Pullups

     P1REN |= 0xC0;                       // P1.6 & P1.7 Pullups

     P1DIR = 0xFF;                        // Unused pins as outputs

     P2OUT = 0;

     P2DIR = 0xFF;

     USICTL0 = USIPE6+USIPE7+USIMST+USISWRST;// Port & USI mode setup

     USICTL1 = USII2C+USIIE;              // Enable I2C mode & USI interrupt

     USICKCTL = USIDIV_7+USISSEL_2+USICKPL;// Setup USI clocks: SCL = SMCLK/8 (~120kHz)

     USICNT |= USIIFGCC;                  // Disable automatic clear control

     USICTL0 &= ~USISWRST;                // Enable USI

     USICTL1 &= ~USIIFG;                  // Clear pending flag

     _EINT();

    //I2Cwrite(0xc0, 0x08, 0x90);

    //I2Cwrite(0xc0, 0x10, 0x90);

    //I2Cwrite(0xc0, 0x07, 0xB0);

    //I2Cwrite(0x90, 0x01, 0xaa);

     while(1)

     {

    I2Cwrite(0xc0, 0x03, 0xe8);

    //I2Cwrite(0xc0, 0x10, 0x90);

    //I2Cwrite(0xb0, 0x03, 0xc5);

    //   I2Cread(0xc0,  0x08);

    //   I2Cread(0xc0,  0x10);

    //   I2Cread(0xc0,  0x07);

    //   I2Cread(0x90,  0x04);

    //   I2Cread(0x90,  0x05);

      I2Cread(0xb0,  0x03);

      I2Cread(0xc0,  0x03);

     }

    }

    /******************************************************

    // USI interrupt service routine

    ******************************************************/

    #pragma vector = USI_VECTOR

    __interrupt void USI_TXRX (void)

    {

     switch(I2C_State)

       {

       case 0: // Generate Start Condition & send address to slave

                 P1OUT |= 0x01;           // LED on: sequence start

                 USISRL = 0x00;           // Generate Start Condition...

                 USICTL0 |= USIGE+USIOE;

                 USICTL0 &= ~USIGE;

                 USISRL = addr;       // ... and transmit address, R/W = 1

                 USICNT = 0x08; // Bit counter = 8, TX Address

                 I2C_State = 2;           // Go to next state: receive address (N)Ack

                 break;

         case 2: // Receive Address Ack/Nack bit

                 USICTL0 &= ~USIOE;       // SDA = input

                 USICNT |= 0x01;          // Bit counter = 1, receive (N)Ack bit

                 I2C_State = 4;           // Go to next state: check (N)Ack

                 break;

         case 4: // Send Reg

                   USICTL0 |= USIOE;        // SDA = output

                   USISRL = reg;

                   USICNT |=  0x08;       // Bit counter = 8, RX data                                

                   I2C_State = 5;         // Go to next state: Test data and (N)Ack

                  break;

       case 5: // Receive Reg Ack/Nack bit

                 USICTL0 &= ~USIOE;       // SDA = input

                 USICNT |= 0x01;          // Bit counter = 1, receive (N)Ack bit

                 if(RW==0)

                 I2C_State = 6;           // Go to next state: send data

                 else

                 I2C_State = 7;

                 break;

        case 6: // Send Data

                 USICTL0 |= USIOE;        // SDA = output

                 USISRL = data;          // ... and transmit address, R/W = 1

                 USICNT = 0x08;         // Bit counter = 8, TX Address

                 I2C_State = 10;       // Go to next state: receive address (N)Ack

                 break;

       case 7: // Generate Start Condition & send address to slave

                 i2c_usi_mst_gen_repeated_start();

    //              USISRL = 0x00;           // Generate Start Condition...

    //              USICTL0 |= USIGE+USIOE;

    //              USICTL0 &= ~USIGE;

                 //USICTL0 |= USIOE;       // SDA = Output

                 USISRL = addr|0x01;       // ... and transmit address, R/W = 1

                 USICNT = 0x08; // Bit counter = 8, TX Address

                 I2C_State = 8;           // Go to next state: receive address (N)Ack

                 break;

       case 8:

                 USICTL0 &= ~USIOE;       // SDA = input

                 USICNT |= 0x01;          // Bit counter = 1, receive (N)Ack bit

                 I2C_State = 9;

                 break;

       case 9: //Read only    Read back

                USICTL0 &= ~USIOE;       // SDA = input

                USICNT |= 0x08;          // Bit counter =8 Reg read back

                USICTL0 |= USIOE;       // SDA = Output

                USISRL = 0xff;

                USICNT |= 0x01;          // Bit counter =8 Reg read back

                I2C_State = 11;

                break;

         case 10: // Receive Data Ack/Nack bit

                 USICTL0 &= ~USIOE;       // SDA = input

                 USICNT |= 0x01;          // Bit counter = 1, receive (N)Ack bit

                 I2C_State = 11;

                 break;    

         case 11: // Prep Stop Condition

                 USICTL0 |= USIOE;        // SDA = output

                 USISRL = 0x00;

                 USICNT |=  0x01;         // Bit counter = 1, SCL high, SDA low

                 I2C_State = 12;          // Go to next state: generate Stop

                 break;

         case 12: // Generate Stop Condition

                 USISRL = 0x0FF;          // USISRL = 1 to release SDA

                 USICTL0 |= USIGE;        // Transparent latch enabled

                 USICTL0 &= ~(USIGE+USIOE);// Latch/SDA output disabled

                 I2C_State = 0;           // Reset state machine for next transmission

                 break;

       }

     USICTL1 &= ~USIIFG;                  // Clear pending flag

    }

    void I2Cwrite(char addr1, char reg1, char data1)

    {

    addr=addr1, reg=reg1, data=data1;

    RW=0;

     USICTL1 |= USIIFG;                 // Set flag and start communication

    for (i = 0; i < 500; i++);

    }

    void I2Cread(char addr1, char reg1)

    {

    addr=addr1, reg=reg1;

                         //RW bit =1

    RW=1;

    USICTL1 |= USIIFG;                 // Set flag and start communication

    for (i = 0; i < 500; i++);

    }