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.

[参考译文] MSPM0C1104:使用 BQ76952读取 I2C 存储器时出现问题

Guru**** 2589280 points
Other Parts Discussed in Thread: MSPM0L1306, BQ76952, MSPM0C1104, SYSCONFIG

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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1318653/mspm0c1104-issue-with-i2c-memory-read-with-bq76952

器件型号:MSPM0C1104
主题中讨论的其他器件:BQ76952、MSPM0L1306、、 SysConfig

亲爱的妈妈:

  我使用 M0C1104 (TSSOP20封装)进行 i2c 通信。 在 CSS 中、我在使用带有 EEPROM 的 I2C (M24C08)和 BQ76952读取存储器位置时遇到问题。

我能够在某些内存位置读取正确的数据、但在其他位置、我得到了垃圾数据。

经测试的 I2C SCL 时钟对于 EEPROM 为100kHz/400kHz、对于 BQ76952为400kHz。

使用的函数:I2C_ReadReg (command、RX_Data、2);

7位 I2C_TARGET_ADDRESS = 0x50 (对于 EEPROM 0xA0 >>1)  和0x08 (对于 bQ76952 0x10 >> 1)

#include "BQ769x2_protocol.h"


uint8_t RX_Data[4];
volatile uint8_t COMMAND = 0x0E;

int main(void)
{
   SYSCFG_DL_init();
  DL_SYSCTL_disableSleepOnExit();

  while (1)
  {
    I2C_ReadReg(COMMAND, RX_Data, 2);
  }
}

根据您关于将 带有 MSPM0L1306的 BQ76952代码迁移到 MSPS003FX 供我们控制器使用的建议、我们使用了建议的流程。

但我们无法理解、我们在演示过程中发现以下问题:

"Cortex_M0P:加载程序:程序的一个或多个部分落入无法写入的存储器区域。  

这些区域实际上不会写入目标。  请检查您的链接器配置和/或存储器映射。"

 

请向我们提供  MSPM0C1104的 BQ76952示例代码、并 帮助我们解决 I2C 无法正常工作的可能问题。

谢谢!

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

    您好  

    以下是应用手册: 基于 MSPM0通过 I2C 的 BQ769x2控制(TI.com) 、希望它能为您提供帮助。

    对于 EEPROM 读取、请尝试使用 SDK 中的演示代码。

    B.R.

    佐伊

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

    您好

    实际上、这并没有解决我的问题。

    我们需要一个 BQ769x2的特定示例、它采用 MSPM0C1104和 TSSOP 封装。

    在将您的代码示例迁移到  MSPS003FX (这是获取 MSPM0C1104并采用 TSSOP 封装的解决方案)时、我将收到以下错误信息。

    "Cortex_M0P:加载程序:程序的一个或多个部分落入无法写入的存储器区域。  

    这些区域实际上不会写入目标。  请检查您的链接器配置和/或存储器映射。"

    请指导我如何消除此错误还提供了 一个采用 MSPM0C1104 TSSOP 封装的 BQ769x2的特定示例。

    B.R.

    绍拉布  

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

    您好!

    您的主要目的是将示例代码从 L1306迁移到 C1104 TSSOP 封装。  

    但我检查了代码、它仅使用 L1306上的 I2C 端口(PA0和 PA1)。 C1104 TSSOP 封装还具有 PA0和 PA1。 这两个 MCU 之间不应进行任何更改。 我也觉得你有一个关于 C1104 MCU 的工作项目。 但是、I2C 通信存在一些问题。 您能详细描述一下这个问题、以便我们提供帮助吗?

    Unknown 说:
    我可以读取某些内存位置的正确数据,但在其他位置我得到了垃圾数据。

    此致、

    现金豪

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

    您好!

    是的、我检查了 BQ76952的 L1306示例中具有  适用于 I2C 的 PA0和 PA1引脚。

    是的、 我们的主要目的是将 BQ76952的示例代码从 L1306迁移到 C1104 TSSOP 封装。  

    I2C 存在以下问题:

    我 使用 M0C11004 (VSSOP)从 Resource Explorer 中打开了 i2c_controller_rw_multibyte_fifo_poll 示例。

    我编辑了其主要函数并添加了 BQ76952 示例中的所有函数 、以读取电池电压。

    结果是我没有获得任何值。

    仅当我在  I2C_ReadReg (  )函数中添加 DL_I2C_flushControllerTXFIFO (I2C_INST);函数时

    然后我在 CellVoltage 数组中接收值,但这些值与电池电压不精确。

    这是我的代码。

    /*
     * Copyright (c) 2021, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include "ti_msp_dl_config.h"
    /*
     * Number of bytes to send from Controller to target.
     *  This example uses FIFO with polling, and the maximum FIFO size is 4.
     *  Refer to interrupt examples to handle larger packets
     */
    #define I2C_TX_PACKET_SIZE (2)
    
    /*
     * Number of bytes to received from target.
     *  This example uses FIFO with polling, and the maximum FIFO size is 4.
     *  Refer to interrupt examples to handle larger packets
     */
    #define I2C_RX_PACKET_SIZE (4)
    
    #define Cell1Voltage 0x14
    #define StackVoltage 0x34
    #define PACKPinVoltage 0x36
    #define Cell16Voltage 0x32
    #define R 0         //Read
    
    void I2C_Send();
    void I2C_Receive_Controller();
    void delayUS(uint16_t us);
    void I2C_ReadReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count);
    void DirectCommands(uint8_t command, uint16_t data, uint8_t type);
    uint16_t BQ769x2_ReadVoltage(uint8_t command);
    void BQ769x2_ReadAllVoltages();
    
    
    /* Data sent to the Target */
    uint8_t gTxPacket[I2C_TX_PACKET_SIZE] = {0x14};
    /* Data received from Target */
    uint8_t gRxPacket[2];
    uint16_t CellVoltage[16];
    /* I2C Target address */
    #define I2C_TARGET_ADDRESS   (0x08)//(0x48)
    
    uint32_t gTxLen, gTxCount;
    uint8_t RX_data[2];
    
    uint16_t Cell_voltage;
    uint16_t Stack_Voltage = 0x00;
    uint16_t Pack_Voltage  = 0x00;
    uint16_t LD_Voltage    = 0x00;
    
    
    void delayUS(uint16_t us)
    {  // Sets the delay in microseconds.
        uint16_t ms;
        char i;
        ms = us / 1000;
        for (i = 0; i < ms; i++) delay_cycles(32000);
    }
    
    //************I2C read register **********************
    void I2C_ReadReg(uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
    {
        DL_I2C_fillControllerTXFIFO(I2C_INST, &reg_addr, count);
    
        /* Wait for I2C to be Idle */
        while (!(DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_IDLE));
    
        DL_I2C_startControllerTransfer(I2C_INST, I2C_TARGET_ADDRESS, DL_I2C_CONTROLLER_DIRECTION_TX, 1);
    
        while (DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS) ;
        /* Trap if there was an error */
        if (DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_ERROR)
        {
            /* LED will remain high if there is an error */
            __BKPT(0);
        }
        /* Wait for I2C to be Idle */
        while (!(DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_IDLE));
        /* Add delay between transfers */
        delay_cycles(1000);
        DL_I2C_flushControllerTXFIFO(I2C_INST);
    
        /* Send a read request to Target */
        DL_I2C_startControllerTransfer(I2C_INST, I2C_TARGET_ADDRESS, DL_I2C_CONTROLLER_DIRECTION_RX, count);
    
        for (uint8_t i = 0; i < count; i++)
        {
            while (DL_I2C_isControllerRXFIFOEmpty(I2C_INST));
            reg_data[i] = DL_I2C_receiveControllerData(I2C_INST);
        }
    }
    
    void DirectCommands(uint8_t command, uint16_t data, uint8_t type)
    // See the TRM or the BQ76952 header file for a full list of Direct Commands
    {  //type: R = read, W = write
        uint8_t TX_data[2] = {0x00, 0x00};
    
        //little endian format
        TX_data[0] = data & 0xff;
        TX_data[1] = (data >> 8) & 0xff;
    
        if (type == R) {                       //Read
            I2C_ReadReg(command, RX_data, 2);  //RX_data is a global variable
            delayUS(2000);
            delayUS(2000);  //success in 100k
        }
    //    if (type == W) {  //write
    //        //Control_status, alarm_status, alarm_enable all 2 bytes long
    //        I2C_WriteReg(command, TX_data, 2);
    //        delayUS(2000);
    //        delayUS(2000);
    //    }
    }
    
    uint16_t BQ769x2_ReadVoltage(uint8_t command)
    // This function can be used to read a specific cell voltage or stack / pack / LD voltage
    {
        //RX_data is global var
        DirectCommands(command, 0x00, R);
        if (command >= Cell1Voltage &&
            command <= Cell16Voltage) {  //Cells 1 through 16 (0x14 to 0x32)
            return (RX_data[1] * 256 + RX_data[0]);  //voltage is reported in mV
        } else {                                     //stack, Pack, LD
            return 10 * (RX_data[1] * 256 +
                            RX_data[0]);  //voltage is reported in 0.01V units
        }
    }
    
    void BQ769x2_ReadAllVoltages()
    // Reads all cell voltages, Stack voltage, PACK pin voltage, and LD pin voltage
    {
        unsigned char x;
        int cellvoltageholder = Cell1Voltage;  //Cell1Voltage is 0x14
        for (x = 0; x < 16; x++) {             //Reads all cell voltages
            CellVoltage[x]    = BQ769x2_ReadVoltage(cellvoltageholder);
            cellvoltageholder = cellvoltageholder + 2;
        }
        Stack_Voltage = BQ769x2_ReadVoltage(StackVoltage);
        Pack_Voltage  = BQ769x2_ReadVoltage(PACKPinVoltage);
    }
    
    int main(void)
    {
      SYSCFG_DL_init();
      DL_SYSCTL_disableSleepOnExit();
      while (1) {
    
          BQ769x2_ReadAllVoltages();
    //      I2C_ReadReg();
    //      Cell_voltage =  gRxPacket[1]* 256 +  gRxPacket[0];
         //I2C_Send();
         //I2C_Receive_Controller();
          delayUS(5000);
          }
    }
    
    

     如果我 将 BQ76952的示例代码从 L1306迁移到  MSPS003FX (TSSOP)并执行上面提到的所有操作。

    然后、在切换到调试模式时、我的 resume (F8)选项被禁用、并且我在控制台中收到以下消息:

    Cortex_M0P:加载程序:程序的一个或多个部分落入无法写入的内存区域。  这些区域实际上不会写入目标。  检查链接器配置和/或存储器映射。

    请帮助我如何从 这个消息中克服。 我在互联网上搜索了这条消息、但找不到任何容易 理解的解决方案。

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

    您好!

    我 将 BQ76952的示例代码从 L1306迁移到 C1104 TSSOP 封装。  

    我将原始输入引脚从 PA14更改为 PA16、因为 C1104 TSSOP 封装没有 PA14引脚。  

    将 ti_msp_dl_config.c 和 ti_msp_dl_config.h 复制到 empty_non_sysconfig 工程。 构建项目时不会发生错误。 您可以尝试一下。  

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

    图片。  e2e.ti.com/.../empty_5F00_non_5F00_sysconfig_5F00_LP_5F00_MSPM0C1104_5F00_nortos_5F00_ticlang.zip