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.

[参考译文] CC2543:LIS2DE12TR 的 I2C 通信问题

Guru**** 2394305 points
Other Parts Discussed in Thread: CC2543

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/other-wireless-group/other-wireless/f/other-wireless-technologies-forum/1061780/cc2543-i2c-communication-problem-with-lis2de12tr

器件型号:CC2543

根据  示例代码、我使用 I2C 将 CC2543与 LIS2DE12TR 连接。

但无法使用寄存器地址读取特定寄存器。 因为我不了解如何发送寄存器地址、以及   在发送寄存器地址后 I2CSTAT 的状态是什么。

我还阅读了用户指南20.1.4.2主机模式、了解 I2CSTAT 寄存器的状态。

所以如果有人知道的话,请帮我…

谢谢  

CC2543用作 主器件

#pragma vector = I2C_VECTOR
__interrupt void I2C_ISR(void)
{

// Clear I2C CPU interrupt flag.
I2CIF = 0;


// If a Start or Restart condition has been transmitted ...
if (I2CSTAT == 0x08 || I2CSTAT == 0x10)
{
// Send Slave address and R/W access.
I2CDATA = (SLAVE_ADDRESS << 1) | READ_FROM_SLAVE;

// End Start condition.
I2CCFG &= ~I2CCFG_STA;
}

// If a Data byte has been received and acknowledge has been returned...
else if (I2CSTAT == 0x50)
{
// Read Data byte.
buffer[bufferIndex++] = I2CDATA;
}

// If finished receiving...
if (bufferIndex >= BUFFER_SIZE )
{
// Generate Stop condition.
I2CCFG |= I2CCFG_STO;



// Disable interrupt from I2C by setting [IEN2.I2CIE = 0].
IEN2 &= ~IEN2_I2CIE;

}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    这是示例代码..........

    #include <hal_types.h>
    // Include Name definitions of individual bits and bit-fields in the CC254x device registers.
    #include <ioCC254x_bitdef.h>
    // Include device specific file
    #if (chip==2541)
    #include "ioCC2541.h"   
    #elif (chip==2543)
    #include "ioCC2543.h"
    #elif (chip==2545)
    #include "ioCC2545.h"
    #else
    #error "Chip not supported!"
    #endif
    
    
    /***********************************************************************************
    * CONSTANTS
    */
    
    // Define size of buffer and number of bytes to send
    #define BUFFER_SIZE 0xFF
    #define SLAVE_ADDRESS 0x53    // 7-bit addressing
    
    #define READ_FROM_SLAVE 0x01
    #define WRITE_TO_SLAVE 0x00
    
    
    /***********************************************************************************
    * LOCAL VARIABLES
    */
    
    // Masters's transmit buffer.
    static uint8 buffer[BUFFER_SIZE];
    static uint16 bufferIndex = 0;
    
    
    /***********************************************************************************
    * LOCAL FUNCTIONS
    */
    
    /***********************************************************************************
    * @fn          I2C_ISR
    *
    * @brief       Function which sends the next I2C data byte.
    *
    * @param       none
    *
    * @return      0
    */
    #pragma vector = I2C_VECTOR
    __interrupt void I2C_ISR(void)
    { 
    #if(chip==2541)
        // Clear I2C CPU interrupt flag.
        P2IF = 0;
    #else
        // Clear I2C CPU interrupt flag.
        I2CIF = 0;
    #endif
      
        // If a Start or Restart condition has been transmitted ...
        if (I2CSTAT == 0x08 || I2CSTAT == 0x10)
        {
            // Send Slave address and R/W access.
            I2CDATA = (SLAVE_ADDRESS << 1) | READ_FROM_SLAVE;
        
            // End Start condition.
            I2CCFG &= ~I2CCFG_STA;
        }
    
        // If a Data byte has been received and acknowledge has been returned...
        else if (I2CSTAT == 0x50)
        {
            // Read Data byte.
            buffer[bufferIndex++] = I2CDATA;
        }
      
        // If finished receiving...
        if (bufferIndex >= BUFFER_SIZE )
        {
            // Generate Stop condition.
            I2CCFG |= I2CCFG_STO;
    
    #if(chip==2541)
            // Disable interrupt from I2C by setting [IEN2.I2CIE = 0].
            IEN2 &= ~IEN2_P2IE;
    #elif(chip==2543 || chip==2545)
            // Disable interrupt from I2C by setting [IEN2.I2CIE = 0].
            IEN2 &= ~IEN2_I2CIE;
    #endif
        
            // Set SRF05EB LED1.
            P1_0 = 1;  
        }
    
        // I2CCFG.SI flag must be cleared by software at the end of the ISR.
        I2CCFG &= ~I2CCFG_SI;
    }
    
    
    /***********************************************************************************
    * @fn          main
    *
    * @brief       Send data to a single slave using I2C in Master mode
    *
    * @param       void
    *
    * @return      0
    */
    int main(void)
    {
        /****************************************************************************
        * Clock setup
        * See basic software example "clk_xosc_cc254x"
        */
      
        // Set system clock source to HS XOSC, with no pre-scaling.
        CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_32M;
        // Wait until clock source has changed.
        while (CLKCONSTA & CLKCON_OSC);
      
        // Note the 32 kHz RCOSC starts calibrating, if not disabled.
    
    #if (chip==2543)
        /***************************************************************************
        * Setup I/O ports
        *
        * Port and pins used by I2C, at the alternative 1 location:
        * I2C SCL:   P0_6    (Debug Connector P18_5)
        * I2C SDA:   P0_7    (Debug Connector P18_3)
        */
    
        // Configure I2C for location Alternative 1.
        PERCFG &= ~PERCFG_I2CCFG;
      
        // Give priority to I2C over Timer 1 for port 0 pins.
        PPRI &= ~PPRI_PRI1P0;
    
        // Set P0_6 and P0_7 as peripheral I/O.
        P0SEL |= BIT7 | BIT6;
    
    #elif(chip==2545)
        /***************************************************************************
        * Setup I/O ports
        *
        * Port and pins used by I2C, at the alternative 2 location:
        * I2C SCL:   P2_5    (Debug Connector P18_5)
        * I2C SDA:   P2_6    (Debug Connector P18_3)
        */
    
        // Configure I2C for location Alternative 2.
        PERCFG |= PERCFG_I2CCFG;
       
        // Give priority to I2C over USART0, then Timer3.
        PPRI = (PPRI & ~PPRI_PRI1P1) | PPRI_PRI1P1_I2C;
    
        // Set P2_5 and P2_6 as peripheral I/O.
        P2SEL |= BIT6 | BIT5;
      
    #elif(chip==2541)
        /***************************************************************************
        * Setup I/O ports
        *
        * CC2541 has dedicated I2C ports
        * I2C SCL:   Pin 2   (Debug Connector P18_5)
        * I2C SDA:   Pin 3   (Debug Connector P18_3)
        */
    
        // Enable I2C on CC2541.
        I2CWC &= ~0x80;
    #endif
    
        // Configure P1_0 as GPIO output for LED1.
        P1SEL &= BIT0;      // GPIO.
        P1DIR |= BIT0;      // Output.
        P1_0 = 0;           // LED1 off.
    
    
      /***************************************************************************
      * Setup interrupt
      */
    
    #if(chip==2541)
        // Clear I2C (P2) CPU interrupt flag.
        P2IF = 0;
    
        // Enable interrupt from I2C by setting [IEN2.P2IE = 1].
        IEN2 |= IEN2_P2IE;
    #elif(chip==2543 || chip==2545)
        // Clear I2C CPU interrupt flag.
        I2CIF = 0;
    
        // Enable interrupt from I2C by setting [IEN2.I2CIE = 1].
        IEN2 |= IEN2_I2CIE;
    #endif
    
        // Enable global interrupts.
        EA = 1;
    
    
        /***************************************************************************
        * Configure I2C
        */
    
        // Enable the I2C module with 33 kHz clock rate.
        // Enable Assert Acknowledge (AA bit).
        // The STArt bit signals a master.
        I2CCFG = (I2CCFG & ~I2CCFG_CR) | I2CCFG_CR_DIV_960 | I2CCFG_ENS1 | I2CCFG_AA | I2CCFG_STA;
    
    
        /* Main Loop, the transfers are interrupt handled. */
        while(1);
    
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Dharmendra、

    您需要进一步熟悉  LIS2DE12TR 、并使用逻辑分析仪/示波器确保 I2C 接口遵循数据表中定义的时序图和格式。  同一数据表还应包含正确的 SLAVE_ADDRESS 值以及 有关 LIS2DE12TR 根据 给定命令给出的响应的更多信息。  请确保也使用了正确的外部上拉电阻器、并且在 ISR 结束时由软件清除 I2CCFG.SI 标志。

    此致、
    Ryan

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢 Ryan

    您能给我推荐 CC2543的 I2C 示例吗?
    CC2543可与任何 I2C 传感器通信并读取 传感器寄存器、无论是否使用库。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    通过前面提到的 CC2543示例、您可以参阅使用具有相同 I2C 外设和功能操作的 CC254X 器件的 BLE 示例。  因此、I2C 资源可以直接复制和应用、此外、我怀疑您可以通过在线搜索找到更多示例。

    https://e2e.ti.com/f/1/t/172539 
    https://e2e.ti.com/f/1/t/376688 

    此致、
    Ryan

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢 Ryan 的帮助和快速回复。。